Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #30 + CI3 update + little improvements and fixes #69

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 16 additions & 155 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
# [A3M (Account Authentication & Authorization)] (https://github.com/donjakobo/A3M/)
_2/25/2013 - Currently some code is semi-stable, please fork and help squash bugs/update views_
# A3M
###

_6/25/2013 - Started working on integrating the main code with admin panel and the development version of CodeIgniter 3_
A3M (Account Authentication & Authorization) is a CodeIgniter 3.x package that leverages bleeding edge web technologies
like OpenID and OAuth to create a user-friendly user experience. It gives you the CRUD to get working right away
without too much fuss and tinkering! Designed for building webapps from scratch without all that tiresome
login / logout / admin stuff thats always required.

A CodeIgniter 3.x package that leverages bleeding edge web technologies like OpenID and OAuth to create a user-friendly user experience. It gives you the CRUD to get working right away without too much fuss! A3M is a full package meant for building websites from scratch without all that tiresome login / logout / admin stuff thats always required.
## Original Authors

## Authors

**Jakub**
+ [@kubanishku](https://twitter.com/kubanishku/) on Twitter
+ [@donjakobo](https://github.com/donjakobo) on GitHub

**PengKong**
+ [@pengkong](https://github.com/pengkong) on Github

**Jakub** [@kubanishku](https://twitter.com/kubanishku/)
**PengKong** [@pengkong](https://github.com/pengkong)

## Key Features & Design Goals

See our **[app task board on Trello](https://trello.com/board/a3m/512c08b874b855f26200e690)** to get a glimps of to-do items

* Native Sign Up, Sign In with 'Remember me' and Sign Out
* Native account Forgot Password and Reset Password
* Facebook/Twitter/Google/Yahoo/OpenID Sign Up, Sign In and Sign Out
Expand Down Expand Up @@ -54,145 +49,11 @@ See our **[app task board on Trello](https://trello.com/board/a3m/512c08b874b855
* GMP or Bcmatch

## Installation Instructions
Check out our wiki: https://github.com/donjakobo/A3M/wiki/Installation-Instructions
for help on getting started.

+ Download the latest version of [A3M](https://github.com/donjakobo/A3M/)
+ Extract to a folder accessible on your webserver (`/` or something like `/a3m/` )
+ Create a database by importing `a3m_database.sql` script found it root folder of package
+ Configure `/application/config/config.php` & `database.php` to match your CI setup (domain + database credentials)
+ Modify `.htaccess` file if your app location is different than `/` (example: `domain.com/a3m/`)
+ Configure `/application/config/account/*` files to reflect your setup (reCAPTCHA, twitter, facebook, openid providers, etc;)

### Twitter configuration:
##### Twitter site (`https://dev.twitter.com/apps`)
+ Create an App and note down the "Consumer key" and "Consumer secret" values
+ Callback URL: `https://www.yoursite.com/account/connect_twitter/`
+ Allow this application to be used to Sign in with Twitter [X]

##### A3M
+ Edit `application/config/account/twitter.php` and insert your consumer key and consumer secret.

##### Testing on localhost
+ localhost and 127.0.0.1 will not work. Use your internal IP (eg. 192.168.1.10)

### Facebook configuration:
##### Facebook Developers site (`https://developers.facebook.com/apps`)
+ Create new App
+ Note down "App ID" and "App Secret" values
+ Tick "Website with Facebook Login" URL: `http://www.yoursite.com`

##### A3M
+ Edit `application/config/account/twitter.php` and insert your consumer key and consumer secret.

##### Testing on localhost
+ Facebook login seems to only work on a live environment (see https://github.com/donjakobo/A3M/issues/3)

### Google / OpenID configuration:
+ Those should work out of the box. No further configuration needed.

##### Testing on localhost
+ Some webservers (XAMMP) have outdated certificates. If you get a `Fatal error: Call to a member function addExtension() on a non-object in` error you must do the following:

edit
`application/helpers/account/Auth/Yadis/ParanoidHTTPFetcher.php` and add
`curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);` after line 140 (before `curl_exec($c);`)

**WARNING: DO NOT DO THIS ON YOUR PRODUCTION/LIVE WEB SERVER AS THIS LEAVES YOUR SERVER VURNERABLE TO MITM ATACKS**

### Yahoo! configuration:
+ No further configuration needed.

##### Testing on localhost
+ Testing on localhost works without any changes.

## Authorization, Roles, and Permissions:

+ Connect to your database and insert a new row into the "a3m_rel_account_role" with the Role ID for Admin (by default this is "1") and the Account ID you want to give Admin Rights to.
+ After you login to the website you should see a few new options under your account for Manage Users, Manage Roles, and Manage Permissions.

### Example: Create an Authors Role with permissions to "Post New Articles".

+ Go to "Manage Roles" and create the new "Authors" role.
+ Name: Authors
+ Description: Website Authors that are allowed to post new articles.
+ Permissions: None
+ Jump to "Manage Permissions" and create the "Post New Articles" permission:
+ Key: post_articles
+ Description: Post New Articles
+ Roles: Check the "Authors" Role
+ Now you can check if the currently logged in user has access to certain features in your Controllers. You simply pass in the "Key" of the permission you created, in this case that is "post_articles".

`$this->authorization->is_permitted('post_articles'); //returns boolean value`


## Note
+ The current codebase is _semi-stable_ due to a large re-write effort of the original application and this branch attempt to bring it to CodeIgniter 3. Please fork and help out!
+ Note that twitter doesn't work if your base url is `localhost` and facebook won't work if your base url is `127.0.0.1`. Therefore ensure that your base url is something like `yoursite.com`. One way to do that is to simply [map the hostname](http://en.wikipedia.org/wiki/Hosts_%28file%29) your want to `127.0.0.1` on your development machine.
Your twitter callback URL should take into account whether or not you have enabled SSL in your a3m config
+ `https://domain.com/account/connect_twitter` (SSL **Enabled**)
+ `http://domain.com/account/connect_twitter` (SSL Disabled)

Configuring this wrongly will result in an `EpiOAuthUnauthorizedException` exception being thrown.

## Guide

Bellow you'll find guide to the different A3M libraries. This guide assumes, that you have all the corresponding models and helpers as well.
+ This guide was created by [@AdwinTrave](https://github.com/AdwinTrave) on GitHub.

For starters you should always include `maintain_ssl();` on your pages. In order to maintain your ssl if you have it enabled.

### Authentication

This library makes all the user authentications.

#### is_signed_in()

Returns a boolean value after it checks the session data, that the user is signed in.

#### sign_in()

Signes in user and redirects to given page, either via session data or GET.

Three variables are needed to be passed in:
+ Username/email
+ Password
+ Remember me?

So the code to call to this method will look something like this:

```php
$this->authentication->sign_in($this->input->post('sign_in_username_email', TRUE), $this->input->post('sign_in_password', TRUE), $this->input->post('sign_in_remember', TRUE))
```

If the password and username are correct it will login the user and will redirect to the home page, or it will redirect the user to the page that has been passed via `GET` `continue` or via session session `sign_in_redirect`.

If the login attempt fails for any reason, it will return boolean value of FALSE and increase the session counter of failed attempts, which you can access under `sign_in_failed_attempts`. To make a check that the user didn't pass over the limit you can call this in an if statement:
```php
$this->session->userdata('sign_in_failed_attempts') < $this->config->item('sign_in_recaptcha_offset')
```

Lastly "Remember me?" is a booblean variable which will keep the user signed in for a longer period of time.

#### sign_out()

As name suggests this method signs out the user and destroyes any session data related to that user and redirects to the homepage.

### Authorization

#### is_permitted()

This method has two input variables:

+ Permission key
+ Require all

Permission key can be either one permission value or array of values. If you use an array of values then use the second boolean variable to determine if the user needs to have permission to use all of those keys in order to get access.

Will return boolean value based on if the user has permission for the given key.

#### is_admin()

This method will check if the user is admin.

#### is_role()
## Help and Support
* Found a bug? Try forking and fixing it.
* Open an issue if you want to discuss/highlight it
* Go to StackOverflow under the tag `codeigniter-a3m` http://stackoverflow.com/questions/tagged/codeigniter-a3m if you have implementation issues (installation problems, etc;)

You pass in the name of the role and the function will determine if the user has that role.
24 changes: 20 additions & 4 deletions application/config/account/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
|--------------------------------------------------------------------------
*/
$config['sign_up_recaptcha_enabled'] = FALSE;
$config['sign_up_auto_sign_in'] = TRUE;
$config['sign_up_auto_sign_in'] = TRUE;
$config['sign_up_default_user_group'] = 2;

/*
|--------------------------------------------------------------------------
Expand All @@ -35,7 +36,7 @@
| Forgot Password
|--------------------------------------------------------------------------
*/
$config['forgot_password_recaptcha_enabled'] = TRUE;
$config['forgot_password_recaptcha_enabled'] = TRUE;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -65,8 +66,23 @@
| password_reset_email Reset password sender email
*/
$config['password_reset_expiration'] = 1800;
$config['password_reset_secret'] = '';
$config['password_reset_email'] = 'no-reply@a3m.com';
$config['password_reset_secret'] = '';
$config['password_reset_email'] = 'no-reply@a3m.net';


/*
|--------------------------------------------------------------------------
| Confrimation E-mail for non-social media registration
|--------------------------------------------------------------------------
| account_
| account_email_validate Will send out confirmation email for account email validation
| account_email_validation_required Requires that the e-mail is validated before user can login
| account_email_confirm_sender
*/
$config['account_email_validate'] = TRUE;
$config['account_email_validation_required']= TRUE;
$config['account_email_confirm_sender'] = 'no-reply@a3m.net';



/* End of file account.php */
Expand Down
5 changes: 3 additions & 2 deletions application/config/mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => array('application/pdf', 'application/x-download', 'binary/octet-stream'),
'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'),
'ai' => array('application/pdf', 'application/postscript'),
'eps' => 'application/postscript',
'ps' => 'application/postscript',
Expand Down Expand Up @@ -78,6 +78,7 @@
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'z' => 'application/x-compress',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
Expand All @@ -96,7 +97,7 @@
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
'bmp' => array('image/bmp', 'image/x-windows-bmp'),
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'),
'gif' => 'image/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
Expand Down
7 changes: 5 additions & 2 deletions application/config/user_agents.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'win98' => 'Windows 98',
'windows 95' => 'Windows 95',
'win95' => 'Windows 95',
'windows phone' => 'Windows Phone',
'windows' => 'Unknown Windows OS',
'android' => 'Android',
'blackberry' => 'BlackBerry',
Expand Down Expand Up @@ -80,6 +81,7 @@
// The order of this array should NOT be changed. Many browsers return
// multiple browser types so we want to identify the sub-type first.
$browsers = array(
'OPR' => 'Opera',
'Flock' => 'Flock',
'Chrome' => 'Chrome',
'Opera' => 'Opera',
Expand All @@ -102,7 +104,8 @@
'hotjava' => 'HotJava',
'amaya' => 'Amaya',
'IBrowse' => 'IBrowse',
'Maxthon' => 'Maxthon'
'Maxthon' => 'Maxthon',
'Ubuntu' => 'Ubuntu Web Browser'
);

$mobiles = array(
Expand Down Expand Up @@ -182,7 +185,7 @@
'operamini' => 'Opera Mini',
'opera mini' => 'Opera Mini',
'opera mobi' => 'Opera Mobile',
'fennec' => 'Firefox Mobile',
'fennec' => 'Firefox Mobile',

// Other
'digital paths' => 'Digital Paths',
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function __construct()
// Load the necessary stuff...
$this->load->helper(array('language', 'url', 'form', 'account/ssl'));
$this->load->library(array('account/authentication', 'account/authorization'));
$this->load->model('account/account_model');
$this->load->model('account/Account_model');
}

function index()
Expand All @@ -18,7 +18,7 @@ function index()

if ($this->authentication->is_signed_in())
{
$data['account'] = $this->account_model->get_by_id($this->session->userdata('account_id'));
$data['account'] = $this->Account_model->get_by_id($this->session->userdata('account_id'));
}

$this->load->view('home', isset($data) ? $data : NULL);
Expand Down
16 changes: 8 additions & 8 deletions application/controllers/account/Account_linked.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function __construct()
$this->load->config('account/account');
$this->load->helper(array('language', 'account/ssl', 'url'));
$this->load->library(array('account/authentication', 'account/authorization', 'form_validation'));
$this->load->model(array('account/account_model', 'account/account_facebook_model', 'account/account_twitter_model', 'account/account_openid_model'));
$this->load->model(array('account/Account_model', 'account/Account_facebook_model', 'account/Account_twitter_model', 'account/Account_openid_model'));
$this->load->language(array('general', 'account/account_linked', 'account/connect_third_party'));
}

Expand All @@ -34,14 +34,14 @@ function index()
}

// Retrieve sign in user
$data['account'] = $this->account_model->get_by_id($this->session->userdata('account_id'));
$data['account'] = $this->Account_model->get_by_id($this->session->userdata('account_id'));

// Delete a linked account
if ($this->input->post('facebook_id') || $this->input->post('twitter_id') || $this->input->post('openid'))
{
if ($this->input->post('facebook_id')) $this->account_facebook_model->delete($this->input->post('facebook_id', TRUE));
elseif ($this->input->post('twitter_id')) $this->account_twitter_model->delete($this->input->post('twitter_id', TRUE));
elseif ($this->input->post('openid')) $this->account_openid_model->delete($this->input->post('openid', TRUE));
if ($this->input->post('facebook_id')) $this->Account_facebook_model->delete($this->input->post('facebook_id', TRUE));
elseif ($this->input->post('twitter_id')) $this->Account_twitter_model->delete($this->input->post('twitter_id', TRUE));
elseif ($this->input->post('openid')) $this->Account_openid_model->delete($this->input->post('openid', TRUE));
$this->session->set_flashdata('linked_info', lang('linked_linked_account_deleted'));
redirect('account/account_linked');
}
Expand All @@ -50,7 +50,7 @@ function index()
$data['num_of_linked_accounts'] = 0;

// Get Facebook accounts
if ($data['facebook_links'] = $this->account_facebook_model->get_by_account_id($this->session->userdata('account_id')))
if ($data['facebook_links'] = $this->Account_facebook_model->get_by_account_id($this->session->userdata('account_id')))
{
foreach ($data['facebook_links'] as $index => $facebook_link)
{
Expand All @@ -59,7 +59,7 @@ function index()
}

// Get Twitter accounts
if ($data['twitter_links'] = $this->account_twitter_model->get_by_account_id($this->session->userdata('account_id')))
if ($data['twitter_links'] = $this->Account_twitter_model->get_by_account_id($this->session->userdata('account_id')))
{
$this->load->config('account/twitter');
$this->load->helper('account/twitter');
Expand All @@ -72,7 +72,7 @@ function index()
}

// Get OpenID accounts
if ($data['openid_links'] = $this->account_openid_model->get_by_account_id($this->session->userdata('account_id')))
if ($data['openid_links'] = $this->Account_openid_model->get_by_account_id($this->session->userdata('account_id')))
{
foreach ($data['openid_links'] as $index => $openid_link)
{
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/account/Account_password.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function __construct()
$this->load->config('account/account');
$this->load->helper(array('date', 'language', 'account/ssl', 'url'));
$this->load->library(array('account/authentication', 'account/authorization', 'form_validation'));
$this->load->model('account/account_model');
$this->load->model('account/Account_model');
$this->load->language(array('general', 'account/account_password'));
}

Expand All @@ -34,7 +34,7 @@ function index()
}

// Retrieve sign in user
$data['account'] = $this->account_model->get_by_id($this->session->userdata('account_id'));
$data['account'] = $this->Account_model->get_by_id($this->session->userdata('account_id'));

// No access to users without a password
if ( ! $data['account']->password) redirect('');
Expand All @@ -47,7 +47,7 @@ function index()
if ($this->form_validation->run())
{
// Change user's password
$this->account_model->update_password($data['account']->id, $this->input->post('password_new_password', TRUE));
$this->Account_model->update_password($data['account']->id, $this->input->post('password_new_password', TRUE));
$this->session->set_flashdata('password_info', lang('password_password_has_been_changed'));
redirect('account/account_password');
}
Expand Down
Loading