Skip to content

Commit

Permalink
Merge pull request #72 from AdwinTrave/master
Browse files Browse the repository at this point in the history
CLOSE #30 + CI3 update + little improvements and fixes
  • Loading branch information
donjakobo committed Nov 19, 2013
2 parents 91ed16c + b645dd7 commit 82b140a
Show file tree
Hide file tree
Showing 251 changed files with 35,796 additions and 927 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/A3M.komodoproject
#Ignore log files of any kind
log-*.php

171 changes: 14 additions & 157 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# [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_

_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
Expand Down Expand Up @@ -54,149 +50,10 @@ 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:
+ Those should work out of the box. 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
<<<<<<< HEAD
+ Please fork and help out! Only with your help will this keep growing and getting better.
=======
+ 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!
>>>>>>> pr/60
+ 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()

You pass in the name of the role and the function will determine if the user has that 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;)
7 changes: 6 additions & 1 deletion application/cache/.htaccess
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
deny from all
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
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'] = '[email protected]';
$config['password_reset_secret'] = '';
$config['password_reset_email'] = '[email protected]';


/*
|--------------------------------------------------------------------------
| 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'] = '[email protected]';



/* End of file account.php */
Expand Down
12 changes: 6 additions & 6 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
| 'sess_driver' = the driver to load: cookie (Classic), native (PHP sessions),
| or your custom driver name
| 'sess_valid_drivers' = additional valid drivers which may be loaded
| 'sess_cookie_name' = the name you want for the cookie
| 'sess_cookie_name' = the name you want for the cookie, must contain only [0-9a-z_-] characters
| 'sess_expiration' = the number of SECONDS you want the session to last.
| by default sessions last 7200 seconds (two hours). Set to zero for no expiration.
| 'sess_expire_on_close' = Whether to cause the session to expire automatically
Expand All @@ -295,15 +295,15 @@
| 'sess_time_to_update' = how many seconds between CI refreshing Session Information
|
*/
$config['sess_driver'] = 'cookie';
$config['sess_driver'] = 'cookie';
$config['sess_valid_drivers'] = array();
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

Expand Down
Loading

0 comments on commit 82b140a

Please sign in to comment.