[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [websites/sso-kde-org] /: Add token validation logic
From:       Sayak Banerjee <sayakb () kde ! org>
Date:       2014-07-01 1:38:53
Message-ID: E1X1n25-0003iY-Vb () scm ! kde ! org
[Download RAW message or body]

Git commit 75982b66767a66f7332c2b6a9b5beed1ff7c206b by Sayak Banerjee.
Committed on 01/07/2014 at 01:37.
Pushed by sayakb into branch 'master'.

Add token validation logic

M  +3    -2    app/controllers/TokenController.php
M  +3    -0    app/lang/en/global.php
M  +64   -0    app/lib/Verifier.php
A  +23   -0    app/views/common/notice.blade.php
M  +7    -0    public/css/keychain.css

http://commits.kde.org/websites/sso-kde-org/75982b66767a66f7332c2b6a9b5beed1ff7c206b

diff --git a/app/controllers/TokenController.php b/app/controllers/TokenController.php
index 6dec363..37ccc20 100755
--- a/app/controllers/TokenController.php
+++ b/app/controllers/TokenController.php
@@ -28,11 +28,12 @@ class TokenController extends BaseController {
 	 *
 	 * @access public
 	 * @param  string  $type
-	 * @param  string  $token
+	 * @param  string  $hash
 	 * @return \Illuminate\Support\Facades\View
 	 */
-	public function getVerify($type, $token)
+	public function getVerify($type, $hash)
 	{
+		return Verifier::check($type, $hash);
 	}
 
 }
diff --git a/app/lang/en/global.php b/app/lang/en/global.php
index e8cb835..d9cc3c1 100755
--- a/app/lang/en/global.php
+++ b/app/lang/en/global.php
@@ -22,5 +22,8 @@ return array(
 	"yes"               => "Yes",
 	"no"                => "No",
 	"remove"            => "Remove",
+	"email_verified"    => "Your email address has been verified",
+	"return_profile"    => "Click here to return to your profile",
+	"return_login"      => "Click here to go to the login screen",
 
 );
diff --git a/app/lib/Verifier.php b/app/lib/Verifier.php
index 6e4308a..db1a973 100755
--- a/app/lib/Verifier.php
+++ b/app/lib/Verifier.php
@@ -14,6 +14,7 @@
  */
 
 use App;
+use Auth;
 use Cache;
 use DateTimeZone;
 use HTTPStatus;
@@ -23,6 +24,7 @@ use Token;
 use TokenTypes;
 use User;
 use UserEmail;
+use View;
 
 /**
  * Verifier class
@@ -106,4 +108,66 @@ class Verifier {
 		});
 	}
 
+	/**
+	 * Validates a token based on its type
+	 *
+	 * @static
+	 * @access public
+	 * @param  string  $type
+	 * @param  string  $hash
+	 * @return bool
+	 */
+	public static function check($type, $hash)
+	{
+		// Perform validation based on token type
+		switch ($type)
+		{
+			case 'email':
+
+				// Fetch the token
+				$token = Token::where('permits_type', TokenTypes::EMAIL)->where('token', $hash)->firstOrFail();
+
+				// Verify the associated email
+				$email = UserEmail::findOrFail($token->permits_id);
+				$email->verified = 1;
+				$email->save();
+
+				// Clear the user cache
+				Cache::forget("user.field.data.{$email->user_id}");
+
+				// Delete the token
+				$token->delete();
+
+				// Show a success notice
+				$data = array(
+					'type'    => 'success',
+					'message' => Lang::get('global.email_verified'),
+				);
+
+				if (Auth::check())
+				{
+					$data['return'] = link_to('profile', Lang::get('global.return_profile'));
+				}
+				else
+				{
+					$data['return'] = link_to('auth/login', Lang::get('global.return_login'));
+				}
+
+				return View::make('common/notice', $data);
+
+			case 'password':
+
+				// Fetch the token
+				$token = Token::where('permits_type', TokenTypes::PASSWORD)->where('token', $hash)->firstOrFail();
+
+				// Set the session flag to indicate successful validation
+				Session::set('security.token.validated', true);
+
+				// Delete the token
+				$token->delete();
+
+				return Redirect::to('auth/reset');
+		}
+	}
+
 }
diff --git a/app/views/common/notice.blade.php b/app/views/common/notice.blade.php
new file mode 100755
index 0000000..a4d60fc
--- /dev/null
+++ b/app/views/common/notice.blade.php
@@ -0,0 +1,23 @@
+@extends('common.page')
+
+@section('body')
+	<div class="row">
+		<div class="col-sm-12">
+			<div class="jumbotron text-center">
+				@if ($type == 'success')
+					<span class="glyphicon glyphicon-ok-sign text-xl text-success"></span>
+				@elseif ($type == 'danger')
+					<span class="glyphicon glyphicon-remove-sign text-xl text-danger"></span>
+				@elseif ($type == 'info')
+					<span class="glyphicon glyphicon-info-sign text-xl text-info"></span>
+				@endif
+
+				<p>{{ $message }}</p>
+
+				@if (isset($return))
+					<small>{{ $return }}</small>
+				@endif
+			</div>
+		</div>
+	</div>
+@stop
diff --git a/public/css/keychain.css b/public/css/keychain.css
index 3bee04b..81bce56 100755
--- a/public/css/keychain.css
+++ b/public/css/keychain.css
@@ -14,6 +14,13 @@
 footer {
   margin: 20px;
 }
+.jumbotron .text-xl {
+  font-size: 110px;
+  margin-bottom: 20px;
+}
+.jumbotron small {
+  font-size: 100%;
+}
 .navbar-modal {
   margin: -15px -15px 15px -15px;
   border-radius: 6px 6px 0 0;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic