Skip to content

Commit 1f7adf7

Browse files
committed
Register functionality using satellizer #202
1 parent 7783cf8 commit 1f7adf7

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LoginFormController {
1919
.then((response) => {
2020
this.$auth.setToken(response.data);
2121

22-
//
22+
this.ToastService.show('Logged in successfully.');
2323
})
2424
.catch(this.failedLogin.bind(this));
2525
}
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
<div>
2-
<md-input-container>
3-
<label>Name</label>
4-
<input type="text" ng-model="vm.name">
5-
</md-input-container>
6-
</div>
1+
<form ng-submit="vm.register()">
2+
<div>
3+
<md-input-container>
4+
<label>Name</label>
5+
<input type="text" ng-model="vm.name">
6+
</md-input-container>
7+
</div>
78

8-
<div>
9-
<md-input-container>
10-
<label>Email</label>
11-
<input type="email" ng-model="vm.email">
12-
</md-input-container>
13-
</div>
9+
<div>
10+
<md-input-container>
11+
<label>Email</label>
12+
<input type="email" ng-model="vm.email">
13+
</md-input-container>
14+
</div>
1415

15-
<div>
16-
<md-input-container>
17-
<label>Password</label>
18-
<input type="password" ng-model="vm.password">
19-
</md-input-container>
20-
</div>
16+
<div>
17+
<md-input-container>
18+
<label>Password</label>
19+
<input type="password" ng-model="vm.password">
20+
</md-input-container>
21+
</div>
2122

22-
<md-button type="submit" class="md-primary md-raised">Register</md-button>
23+
<md-button type="submit" class="md-primary md-raised">Register</md-button>
24+
</form>

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1-
class RegisterFormController{
2-
constructor(){
3-
'ngInject';
4-
5-
this.name = '';
6-
this.email = '';
7-
this.password = '';
8-
}
1+
class RegisterFormController {
2+
constructor($auth, ToastService) {
3+
'ngInject';
4+
5+
this.$auth = $auth;
6+
this.ToastService = ToastService;
7+
8+
this.name = '';
9+
this.email = '';
10+
this.password = '';
11+
}
12+
13+
register() {
14+
var user = {
15+
name: this.name,
16+
email: this.email,
17+
password: this.password
18+
};
19+
20+
this.$auth.signup(user)
21+
.then((response) => {
22+
//remove this if you require email verification
23+
this.$auth.setToken(response.data);
24+
25+
this.ToastService.show('Successfully registered.');
26+
})
27+
.catch(this.failedRegistration.bind(this));
28+
}
29+
30+
31+
32+
failedRegistration(response) {
33+
if (response.status === 422) {
34+
for (var error in response.data.errors) {
35+
return this.ToastService.error(response.data.errors[error][0]);
36+
}
37+
}
38+
this.ToastService.error(response.statusText);
39+
}
940
}
1041

1142
export const RegisterFormComponent = {
12-
templateUrl: './views/app/components/register-form/register-form.component.html',
13-
controller: RegisterFormController,
14-
controllerAs: 'vm',
15-
bindings: {}
43+
templateUrl: './views/app/components/register-form/register-form.component.html',
44+
controller: RegisterFormController,
45+
controllerAs: 'vm',
46+
bindings: {}
1647
}
17-
18-

app/Http/Controllers/Auth/AuthController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function postLogin(Request $request)
3333
return response()->success(compact('user', 'token'));
3434
}
3535

36-
public function postRegister()
36+
public function postRegister(Request $request)
3737
{
3838
$this->validate($request, [
3939
'name' => 'required|min:3',

0 commit comments

Comments
 (0)