Skip to content

Commit

Permalink
minor ES6 fixes + reset password page & component #129
Browse files Browse the repository at this point in the history
  • Loading branch information
jadjoubran committed Apr 14, 2016
1 parent d55e62f commit a255922
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
</md-input-container>
</div>

<md-button type="submit" class="LoginForm-submit md-primary md-raised">Submit</md-button>
<md-button type="submit" class="md-primary md-raised">Submit</md-button>
</form>
4 changes: 2 additions & 2 deletions angular/app/components/login-form/login-form.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LoginFormController {
}

login() {
var user = {
let user = {
email: this.email,
password: this.password
};
Expand All @@ -26,7 +26,7 @@ class LoginFormController {

failedLogin(response) {
if (response.status === 422) {
for (var error in response.data.errors) {
for (let error in response.data.errors) {
return this.ToastService.error(response.data.errors[error][0]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RegisterFormController {
}

register() {
var user = {
let user = {
name: this.name,
email: this.email,
password: this.password
Expand All @@ -31,7 +31,7 @@ class RegisterFormController {

failedRegistration(response) {
if (response.status === 422) {
for (var error in response.data.errors) {
for (let error in response.data.errors) {
return this.ToastService.error(response.data.errors[error][0]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="ResetPassword-loader" layout="row" layout-align="center center">
<md-progress-circular md-mode="indeterminate" ng-if="!vm.isValidCode"></md-progress-circular>
</div>

<form ng-submit="vm.submit()" ng-show="vm.isValidCode">
<div>
<md-input-container>
<label>Password</label>
<input type="password" ng-model="vm.password">
</md-input-container>
</div>

<div>
<md-input-container>
<label>Confirm Password</label>
<input type="password" ng-model="vm.password_confirmation">
</md-input-container>
</div>

<md-button type="submit" class="md-primary md-raised">Submit</md-button>
</form>
47 changes: 47 additions & 0 deletions angular/app/components/reset-password/reset-password.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class ResetPasswordController {
constructor(API, ToastService, $state) {
'ngInject';

this.API = API;
this.$state = $state;
this.ToastService = ToastService;

this.password = '';
this.password_confirmation = '';
this.isValidCode = false;

this.validateCode();
}

validateCode() {
let email = this.$state.params.email;
let code = this.$state.params.code;

this.API.all('auth/reset').get('check', {
email, code
}).then(() => {
this.isValidCode = true;
});
}

reset() {
let data = {
email: this.$state.params.email,
code: this.$state.params.code,
password: this.password,
password_confirmation: this.password_confirmation
};

this.API.all('auth/reset').post(data).then(() => {
this.ToastService.show('Password successfully changed');
this.$state.go('app.login');
});
}
}

export const ResetPasswordComponent = {
templateUrl: './views/app/components/reset-password/reset-password.component.html',
controller: ResetPasswordController,
controllerAs: 'vm',
bindings: {}
}
3 changes: 3 additions & 0 deletions angular/app/components/reset-password/reset-password.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ResetPassword-loader{
min-height: 300px;
}
Empty file.
9 changes: 9 additions & 0 deletions angular/app/pages/reset-password/reset-password.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<md-content class="Page-container">
<div layout="column" layout-align="center center">

<h1 class="md-headline">Reset Password</h1>

<reset-password></reset-password>

</div>
</md-content>
15 changes: 10 additions & 5 deletions angular/config/routes.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function RoutesConfig($stateProvider, $urlRouterProvider) {
'ngInject';

var getView = (viewName) => {
let getView = (viewName) => {
return `./views/app/pages/${viewName}/${viewName}.page.html`;
};

Expand All @@ -10,6 +10,7 @@ export function RoutesConfig($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
abstract: true,
data: {},//{auth: true} would require JWT auth
views: {
header: {
templateUrl: getView('header')
Expand All @@ -22,7 +23,6 @@ export function RoutesConfig($stateProvider, $urlRouterProvider) {
})
.state('app.landing', {
url: '/',
data: {},
views: {
'main@': {
templateUrl: getView('landing')
Expand All @@ -31,7 +31,6 @@ export function RoutesConfig($stateProvider, $urlRouterProvider) {
})
.state('app.login', {
url: '/login',
data: {},
views: {
'main@': {
templateUrl: getView('login')
Expand All @@ -40,7 +39,6 @@ export function RoutesConfig($stateProvider, $urlRouterProvider) {
})
.state('app.register', {
url: '/register',
data: {},
views: {
'main@': {
templateUrl: getView('register')
Expand All @@ -49,11 +47,18 @@ export function RoutesConfig($stateProvider, $urlRouterProvider) {
})
.state('app.forgot_password', {
url: '/forgot-password',
data: {},
views: {
'main@': {
templateUrl: getView('forgot-password')
}
}
})
.state('app.reset_password', {
url: '/reset-password/:email/:code',
views: {
'main@': {
templateUrl: getView('reset-password')
}
}
});
}
2 changes: 2 additions & 0 deletions angular/index.components.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {ResetPasswordComponent} from './app/components/reset-password/reset-password.component';
import {ForgotPasswordComponent} from './app/components/forgot-password/forgot-password.component';
import {LoginFormComponent} from './app/components/login-form/login-form.component';
import {RegisterFormComponent} from './app/components/register-form/register-form.component';

angular.module('app.components')
.component('resetPassword', ResetPasswordComponent)
.component('forgotPassword', ForgotPasswordComponent)
.component('loginForm', LoginFormComponent)
.component('registerForm', RegisterFormComponent);
Expand Down
2 changes: 1 addition & 1 deletion angular/run/routes.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function RoutesRun($rootScope, $state, $auth) {
'ngInject';


var deregisterationCallback = $rootScope.$on("$stateChangeStart", function(event, toState) {
let deregisterationCallback = $rootScope.$on("$stateChangeStart", function(event, toState) {

if (toState.data && toState.data.auth) {
/*Cancel going to the authenticated state and go back to the login page*/
Expand Down
6 changes: 3 additions & 3 deletions angular/services/API.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export class APIService {
constructor(Restangular, ToastService, $window) {
'ngInject';
//content negotiation
var headers = {
let headers = {
'Content-Type': 'application/json',
'Accept': 'application/x.laravel.v1+json'
};
Expand All @@ -13,13 +13,13 @@ export class APIService {
.setDefaultHeaders(headers)
.setErrorInterceptor(function(response) {
if (response.status === 422) {
for (var error in response.data.errors) {
for (let error in response.data.errors) {
return ToastService.error(response.data.errors[error][0]);
}
}
})
.addFullRequestInterceptor(function(element, operation, what, url, headers) {
var token = $window.localStorage.satellizer_token;
let token = $window.localStorage.satellizer_token;
if (token) {
headers.Authorization = 'Bearer ' + token;
}
Expand Down
6 changes: 3 additions & 3 deletions angular/services/dialog.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class DialogService {
}

alert(title, content) {
var alert = this.$mdDialog.alert()
let alert = this.$mdDialog.alert()
.title(title)
.content(content)
.ariaLabel(content)
Expand All @@ -34,7 +34,7 @@ export class DialogService {
}

confirm(title, content) {
var confirm = this.$mdDialog.confirm()
let confirm = this.$mdDialog.confirm()
.title(title)
.content(content)
.ariaLabel(content)
Expand All @@ -45,7 +45,7 @@ export class DialogService {
}

prompt(title, content, placeholder) {
var prompt = this.$mdDialog.prompt()
let prompt = this.$mdDialog.prompt()
.title(title)
.textContent(content)
.placeholder(placeholder)
Expand Down
11 changes: 11 additions & 0 deletions tests/angular/app/components/reset-password.component.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ngDescribe({
name: 'Test reset-password component',
modules: 'app',
element: '<reset-password></reset-password>',
tests: function (deps) {

it('basic test', () => {
//
});
}
});

0 comments on commit a255922

Please sign in to comment.