Skip to content

Commit

Permalink
added social icons to login form
Browse files Browse the repository at this point in the history
  • Loading branch information
thyseus committed May 15, 2013
1 parent b3812a4 commit 350806e
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 42 deletions.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -3,11 +3,17 @@ yii-user-management

a user management module collection for the yii framework

It has the following features:
Features:

* An automated Installer
* User Administration
* Role Administration
* Hybrid auth is bundled and can easily be integrated, see docs/hybridauth.txt.
* All providers of hybrid auth and hybrid auth extra package are integrated:
AOL, Google, Mail.ru, Plurk, Tumblr, Yahoo, Disqus, Identica, Murmur, px500,
TwitchTV, Yandex, Facebook, Instagram, MySpace, QQ, Twitter, Foursquare,
LastFM, Odnoklassniki, Sina, Viadeo, GitHub, LinkedIn, OpenID, Skyrock,
Vimeo, Goodreads, Live, Pixnet, Steam, Vkontakte
* Permission System with a mixture of RBAC and ACL (see docs)
* Profiles & Profile history & Profile Comments & Profile Fields Administration
* Messaging System (send/receive Messages between Users) Submodule
Expand Down
2 changes: 1 addition & 1 deletion user/UserModule.php
Expand Up @@ -13,7 +13,7 @@ class UserModule extends CWebModule {
//layout related control vars
public $baseLayout = 'application.views.layouts.main';
public $layout = 'application.modules.user.views.layouts.yum';
public $loginLayout = 'application.modules.user.views.layouts.yum';
public $loginLayout = 'application.modules.user.views.layouts.login';
public $adminLayout = 'application.modules.user.views.layouts.yum';
public $enableBootstrap = true;

Expand Down
1 change: 1 addition & 0 deletions user/assets/css/yum.css
Expand Up @@ -13,3 +13,4 @@ label { display: inline }
.table_profile_fields { width: 50%; }
.profilefieldlabel { float: left; margin-right: 5px; width: 100px;}
.friend { margin: 5px; }
a.social { text-decoration: none; }
Binary file added user/assets/images/facebook.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/google.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/linkedin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/live.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/livejournal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/myspace.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/openid.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/tumblr.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/twitter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/wordpress.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added user/assets/images/yahoo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 14 additions & 25 deletions user/controllers/YumAuthController.php
Expand Up @@ -38,7 +38,8 @@ public function getUser($user) {
}

public function loginByUsername() {
if($this->getUser($this->loginForm->username))
$user = $this->getUser($this->loginForm->username);
if($user)
return $this->authenticate($user);
else {
Yum::log( Yum::t(
Expand Down Expand Up @@ -75,52 +76,40 @@ public function loginByHybridAuth($provider) {
throw new CException(400, 'Hybrid auth needs the profile submodule to be enabled');

Yii::import('application.modules.user.vendors.hybridauth.Hybrid.Auth', true);

require_once(Yum::module()->hybridAuthConfigFile);

try {
$hybridauth = new Hybrid_Auth(Yum::module()->hybridAuthConfigFile);
$providers = Yum::module()->hybridAuthProviders;

if(count($providers) == 0)
throw new CHttpException(400, 'No Hybrid auth providers enabled in configuration file');
throw new CException('No Hybrid auth providers enabled in configuration file');

if(!in_array($provider, $providers))
throw new CHttpException(400, 'Requested provider is not enabled in configuration file');
throw new CException('Requested provider is not enabled in configuration file');

$success = $hybridauth->authenticate($provider);
if($success && $success->isUserConnected()) {
$hybridAuthProfile = $success->getUserProfile();
// User found and authenticated at foreign party. Is he already
// registered at our application?
$hybridAuthProfile = $success->getUserProfile();
$user = $this->getUser($hybridAuthProfile->displayName);
if($user) {
// Yes he is, log in:
$identity = new YumUserIdentity($hybridAuthProfile->displayName, null);
$identity->authenticate(true);
$duration = $this->loginForm->rememberMe ? Yum::module()->cookieDuration : 0;
Yii::app()->user->login($identity, $duration);
} else {
// No, he is not, register and login:
if(!$user) {
// No, he is not, so we register the user and sync the profile fields:
$user = new YumUser();
$profile = new YumProfile();

$profile->firstname = $hybridAuthProfile->firstName;
$profile->lastname = $hybridAuthProfile->lastName;
$profile->email = $hybridAuthProfile->email;

$user->username = $hybridAuthProfile->displayName;
$user->createtime = time();

$user->save(false);
$profile->user_id = $user->id;
$profile->save(false);
$user->registerByHybridAuth($hybridAuthProfile);
}

Yum::log(Yum::t('User {username} logged in by hybrid {provider}', array(
'{username}' => $hybridAuthProfile->displayName,
'{provider}' => $provider)));

$identity = new YumUserIdentity($user->username, null);
$identity->authenticate(true);
$duration = $this->loginForm->rememberMe ? Yum::module()->cookieDuration : 0;
Yii::app()->user->login($identity, $duration);

}
$this->redirect(Yum::module()->returnUrl);
}
} catch (Exception $e) {
Expand Down
24 changes: 16 additions & 8 deletions user/docs/hybridauth.txt
@@ -1,18 +1,26 @@
Using hybridauth with yii-user-management:

0.) Read the Hybrid Auth User Guide to get an idea of what we are doing here:
http://hybridauth.sourceforge.net/userguide.html

1.) Configure 'loginType' in UserModule configuration to include 'hybridauth' in your
application config/main.php
application config/main.php. For example, set 'loginType' to 7, to allow login by
username, email and hybridauth. Make sure to enable the profile submodule.

2.) Select the providers you want to use in the 'hybridAuthProviders' array.
2.) Select the providers you want to use in the 'hybridAuthProviders' array. For example,
to use Facebook and Twitter, set this variable to array('Facebook', 'Twitter')

3.) Take the modules/user/vendors/index.php, rename it to 'hybridauth.php' and place it
beside your application index.php bootstrap script.
beside your application index.php bootstrap script. This will be your hybrid auth
entry script.

4.) Configure and place your hybridauth configuration file. Set the base_url
to the hybridauth.php script configured above.
to the hybridauth.php script configured above.

5.) Place the configuration file into your application
protected/config/hybridauth.php. This path can be configured with the
hybridAuthConfigFile option. You can use the example provided by hybridauth in
user/vendors/hybridauth/config.php to get started.
5.) Place the hybrid auth configuration file into your application
protected/config/hybridauth.php. If necessary, this path can be configured with
the hybridAuthConfigFile option. You can use the example provided by
hybridauth in user/vendors/hybridauth/config.php to get started.

6.) Navigate to your login page. The configured providers should appear beneath
the login fields.
3 changes: 3 additions & 0 deletions user/docs/install_tutorial.txt
Expand Up @@ -196,6 +196,9 @@ There are some examples on how to extend from the Yii User Management
Module and how to implement project-specific stuff. See the files in
the docs/ directory for all this.

See docs/hybridauth.txt for instruction on how to use the wonderful
hybrid auth framework that is bundled with yii-user-management.


FAQ:
----
Expand Down
3 changes: 2 additions & 1 deletion user/docs/yum_translation.sql
Expand Up @@ -325,6 +325,7 @@ INSERT IGNORE INTO `translation` (`message`, `translation`, `language`, `categor
('Grant permission', 'Berechtigung zuweisen', 'de', 'yum'),
('Grant permission', 'Otorgar permiso', 'es', 'yum'),
('Leave group', 'Gruppe verlassen', 'de', 'yum'),
('You can also login by', 'Anmeldung auch möglich über', 'de', 'yum'),
('You have left this group', 'Du hast diese Gruppe verlassen', 'de', 'yum'),
('Group Name', 'Gruppenname', 'de', 'yum'),
('Group Name', 'Nombre de grupo', 'es', 'yum'),
Expand Down Expand Up @@ -2450,4 +2451,4 @@ INSERT IGNORE INTO `translation` (`message`, `translation`, `language`, `categor
('{attribute} must not contain more than {num} sequentially repeated characters.','{attribute} non deve contenere {num} caratteri ripetuti sequenzialmente.','it','yum'),
('{attribute} must not contain more than {num} sequentially repeated characters.','{attribute} nie moze zawierac wiecej niz {num} sekwencji znakow.','pl','yum'),
('{attribute} must not contain whitespace.','{attribute} non deve contenere spazi.','it','yum'),
('{attribute} must not contain whitespace.','{attribute} nie moze zawierac bialych znakow.','pl','yum');
('{attribute} must not contain whitespace.','{attribute} nie moze zawierac bialych znakow.','pl','yum');
15 changes: 15 additions & 0 deletions user/models/YumUser.php
Expand Up @@ -509,6 +509,21 @@ public function getFriends($everything = false)
return $friends;
}

public function registerByHybridAuth($hybridAuthProfile) {
$profile = new YumProfile();

$profile->firstname = $hybridAuthProfile->firstName;
$profile->lastname = $hybridAuthProfile->lastName;
$profile->email = $hybridAuthProfile->email;

$this->username = $hybridAuthProfile->displayName;
$this->createtime = time();

$this->save(false);
$profile->user_id = $this->id;
$profile->save(false);
}

// Registers a user
public function register($username = null,
$password = null,
Expand Down
24 changes: 24 additions & 0 deletions user/views/layouts/login.php
@@ -0,0 +1,24 @@
<?php
Yii::app()->clientScript->registerCssFile(
Yii::app()->getAssetManager()->publish(
Yii::getPathOfAlias('YumModule.assets.css').'/yum.css'));

$this->beginContent(Yum::module()->baseLayout); ?>

<?php
if (Yum::module()->debug) {
echo CHtml::openTag('div', array('class' => 'yumwarning'));
echo Yum::t(
'You are running the Yii User Management Module {version} in Debug Mode!', array(
'{version}' => Yum::module()->version));
echo CHtml::closeTag('div');
}

Yum::renderFlash();

echo $content;
?>

<div class="clearfix"></div>

<?php $this->endContent(); ?>
33 changes: 27 additions & 6 deletions user/views/user/login.php
Expand Up @@ -12,10 +12,14 @@

<div class="form">

<?php if($model->hasErrors()) { ?>
<div class="alert">
<?php echo CHtml::errorSummary($model); ?>
</div>
<?php } ?>


<div class="span5 loginform">
<p> <?php echo Yum::t(
'Please fill out the following form with your login credentials:'); ?> </p>

Expand All @@ -34,18 +38,30 @@
<?php echo CHtml::activeLabelEx($model,'password'); ?>
<?php echo CHtml::activePasswordField($model,'password'); ?>
</div>
</div>

<?php if(Yum::module()->loginType & UserModule::LOGIN_BY_HYBRIDAUTH && Yum::module()->hybridAuthProviders) { ?>
<div class="row hybridauth">
<?php echo Yum::t('You can also login by: ');
foreach(Yum::module()->hybridAuthProviders as $provider)
echo CHtml::link($provider, $this->createUrl('//user/auth/login', array('hybridauth' => $provider)));
echo '&nbsp;';
<?php if(Yum::module()->loginType & UserModule::LOGIN_BY_HYBRIDAUTH
&& Yum::module()->hybridAuthProviders) { ?>
<div class="span5 hybridauth">
<?php echo Yum::t('You can also login by') . ': <br />';
foreach(Yum::module()->hybridAuthProviders as $provider)
echo CHtml::link(
CHtml::image(
Yii::app()->getAssetManager()->publish(
Yii::getPathOfAlias(
'application.modules.user.assets.images').'/'.strtolower($provider).'.png'),
$provider) . $provider, $this->createUrl(
'//user/auth/login', array('hybridauth' => $provider)), array(
'class' => 'social')) . '<br />';
?>
</div>

<div class="clearfix"></div>

<?php } ?>

<div class="span10">
<div class="row">
<p class="hint">
<?php
if(Yum::hasModule('registration') && Yum::module('registration')->enableRegistration)
Expand All @@ -62,11 +78,16 @@
?>
</p>

</div>


<div class="row">
<div class="buttons">
<?php echo CHtml::submitButton(Yum::t('Login'), array('class' => 'btn')); ?>
</div>

</div>
</div>
</div>

<?php echo CHtml::endForm(); ?>
Expand Down

0 comments on commit 350806e

Please sign in to comment.