Skip to content

Commit 254a84f

Browse files
committed
Login functionality using satellizer #202
1 parent 39b0c35 commit 254a84f

File tree

8 files changed

+50
-34
lines changed

8 files changed

+50
-34
lines changed
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
<div>
2-
<md-input-container class="LoginForm-inputContainer">
3-
<label>Email</label>
4-
<input type="email" ng-model="vm.email">
5-
</md-input-container>
6-
</div>
1+
<form ng-submit="vm.login()">
2+
<div>
3+
<md-input-container class="LoginForm-inputContainer">
4+
<label>Email</label>
5+
<input type="email" ng-model="vm.email">
6+
</md-input-container>
7+
</div>
78

8-
<div>
9-
<md-input-container class="LoginForm-inputContainer">
10-
<label>Password</label>
11-
<input type="password" ng-model="vm.password">
12-
</md-input-container>
13-
</div>
9+
<div>
10+
<md-input-container class="LoginForm-inputContainer">
11+
<label>Password</label>
12+
<input type="password" ng-model="vm.password">
13+
</md-input-container>
14+
</div>
1415

15-
<md-button type="submit" class="LoginForm-submit md-primary md-raised">Login</md-button>
16+
<md-button type="submit" class="LoginForm-submit md-primary md-raised">Login</md-button>
17+
</form>

angular/app/components/login-form/login-form.component.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
class LoginFormController{
2-
constructor(){
3-
'ngInject';
1+
class LoginFormController {
2+
constructor($auth) {
3+
'ngInject';
44

5-
this.email = '';
6-
this.password = '';
7-
}
5+
this.$auth = $auth;
6+
7+
this.email = '';
8+
this.password = '';
9+
}
10+
11+
login() {
12+
var user = {
13+
email: this.email,
14+
password: this.password
15+
};
16+
17+
this.$auth.login(user)
18+
.then((response) => {
19+
this.$auth.setToken(response.data.data.token);
20+
});
21+
}
822
}
923

1024
export const LoginFormComponent = {
11-
templateUrl: './views/app/components/login-form/login-form.component.html',
12-
controller: LoginFormController,
13-
controllerAs: 'vm',
14-
bindings: {}
25+
templateUrl: './views/app/components/login-form/login-form.component.html',
26+
controller: LoginFormController,
27+
controllerAs: 'vm',
28+
bindings: {}
1529
}
16-
17-

angular/app/pages/header/header.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div layout="row">
33
<div flex="90" flex-offset="5" class="DemoHeader-container">
44
<div layout="row" layout-align="space-between">
5-
<img src="img/icons/logo.svg" class="DemoHeader-logo"/>
5+
<img src="img/icons/logo.svg" ui-sref="app.landing" class="DemoHeader-logo"/>
66
<div layout="row" layout-align="center stretch" hide-xs>
77
<a class="DemoHeader-link md-subhead" href="https://laravel-angular.readme.io" target="_blank">Docs</a>
88
<a class="DemoHeader-link md-subhead" href="https://www.youtube.com/watch?list=PLIiQ4B5FSupiQYLX6kERPV0OhMC7tTbBE&v=_ZWV9KBK2N8" target="_blank">Screencasts</a>

angular/config/satellizer.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function SatellizerConfig($authProvider) {
55
return true;
66
}
77

8-
$authProvider.loginUrl = '/auth/login';
9-
$authProvider.signupUrl = '/auth/signup';
8+
$authProvider.loginUrl = '/api/auth/login';
9+
$authProvider.signupUrl = '/api/auth/register';
1010

1111
}

app/Http/Controllers/Auth/AuthController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Http\Controllers\Auth;
44

5+
use Auth;
56
use JWTAuth;
67
use App\User;
8+
use Illuminate\Http\Request;
79
use App\Http\Controllers\Controller;
810

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

24-
return response()->success(compact('token'));
26+
$user = Auth::user();
27+
28+
return response()->success(compact('user', 'token'));
2529
}
2630

2731
public function postRegister()

app/Http/routes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@
3939
//protected routes with JWT (must be logged in to access any of these routes)
4040
$api->group(['middleware' => 'api.auth'], function ($api) {
4141

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

config/database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'mysql' => [
5656
'driver' => 'mysql',
5757
'host' => env('DB_HOST', 'localhost'),
58+
'port' => env('DB_PORT', '3306'),
5859
'database' => env('DB_DATABASE', 'forge'),
5960
'username' => env('DB_USERNAME', 'forge'),
6061
'password' => env('DB_PASSWORD', ''),

database/migrations/2014_10_12_000000_create_users_table.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function up()
1717
$table->string('name');
1818
$table->string('email')->unique();
1919
$table->string('password', 60);
20-
$table->rememberToken();
2120
$table->timestamps();
2221
});
2322
}

0 commit comments

Comments
 (0)