Skip to content

Commit

Permalink
Login functionality using satellizer #202
Browse files Browse the repository at this point in the history
  • Loading branch information
jadjoubran committed Mar 22, 2016
1 parent 39b0c35 commit 254a84f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
28 changes: 15 additions & 13 deletions angular/app/components/login-form/login-form.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<div>
<md-input-container class="LoginForm-inputContainer">
<label>Email</label>
<input type="email" ng-model="vm.email">
</md-input-container>
</div>
<form ng-submit="vm.login()">
<div>
<md-input-container class="LoginForm-inputContainer">
<label>Email</label>
<input type="email" ng-model="vm.email">
</md-input-container>
</div>

<div>
<md-input-container class="LoginForm-inputContainer">
<label>Password</label>
<input type="password" ng-model="vm.password">
</md-input-container>
</div>
<div>
<md-input-container class="LoginForm-inputContainer">
<label>Password</label>
<input type="password" ng-model="vm.password">
</md-input-container>
</div>

<md-button type="submit" class="LoginForm-submit md-primary md-raised">Login</md-button>
<md-button type="submit" class="LoginForm-submit md-primary md-raised">Login</md-button>
</form>
36 changes: 24 additions & 12 deletions angular/app/components/login-form/login-form.component.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
class LoginFormController{
constructor(){
'ngInject';
class LoginFormController {
constructor($auth) {
'ngInject';

this.email = '';
this.password = '';
}
this.$auth = $auth;

this.email = '';
this.password = '';
}

login() {
var user = {
email: this.email,
password: this.password
};

this.$auth.login(user)
.then((response) => {
this.$auth.setToken(response.data.data.token);
});
}
}

export const LoginFormComponent = {
templateUrl: './views/app/components/login-form/login-form.component.html',
controller: LoginFormController,
controllerAs: 'vm',
bindings: {}
templateUrl: './views/app/components/login-form/login-form.component.html',
controller: LoginFormController,
controllerAs: 'vm',
bindings: {}
}


2 changes: 1 addition & 1 deletion angular/app/pages/header/header.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div layout="row">
<div flex="90" flex-offset="5" class="DemoHeader-container">
<div layout="row" layout-align="space-between">
<img src="img/icons/logo.svg" class="DemoHeader-logo"/>
<img src="img/icons/logo.svg" ui-sref="app.landing" class="DemoHeader-logo"/>
<div layout="row" layout-align="center stretch" hide-xs>
<a class="DemoHeader-link md-subhead" href="https://laravel-angular.readme.io" target="_blank">Docs</a>
<a class="DemoHeader-link md-subhead" href="https://www.youtube.com/watch?list=PLIiQ4B5FSupiQYLX6kERPV0OhMC7tTbBE&v=_ZWV9KBK2N8" target="_blank">Screencasts</a>
Expand Down
4 changes: 2 additions & 2 deletions angular/config/satellizer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function SatellizerConfig($authProvider) {
return true;
}

$authProvider.loginUrl = '/auth/login';
$authProvider.signupUrl = '/auth/signup';
$authProvider.loginUrl = '/api/auth/login';
$authProvider.signupUrl = '/api/auth/register';

}
10 changes: 7 additions & 3 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Http\Controllers\Auth;

use Auth;
use JWTAuth;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AuthController extends Controller
Expand All @@ -15,13 +17,15 @@ public function postLogin(Request $request)
try {
// verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->error('Invalid credentials', Response::HTTP_UNAUTHORIZED);
return response()->error('Invalid credentials', 401);
}
} catch (\JWTException $e) {
return response()->error('Could not create token', Response::HTTP_INTERNAL_SERVER_ERROR);
return response()->error('Could not create token', 500);
}

return response()->success(compact('token'));
$user = Auth::user();

return response()->success(compact('user', 'token'));
}

public function postRegister()
Expand Down
2 changes: 0 additions & 2 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@
//protected routes with JWT (must be logged in to access any of these routes)
$api->group(['middleware' => 'api.auth'], function ($api) {

$api->get('sample/protected', 'LoginController@protectedData');

});
1 change: 1 addition & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public function up()
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
Expand Down

0 comments on commit 254a84f

Please sign in to comment.