Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10 from heloufir/master
Browse files Browse the repository at this point in the history
Update heloufir/simple-passport
  • Loading branch information
heloufir committed Apr 8, 2019
2 parents 281f97d + 0e91806 commit 9c884de
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 25 deletions.
3 changes: 2 additions & 1 deletion back-end/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App;

use Heloufir\SecurityStarter\Core\UserProfiles;
use Heloufir\SimplePassport\Helpers\CanResetPassword;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable
{
use Notifiable, HasApiTokens, UserProfiles;
use Notifiable, HasApiTokens, UserProfiles, CanResetPassword;

/**
* The attributes that are mass assignable.
Expand Down
36 changes: 18 additions & 18 deletions back-end/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions back-end/config/simple-passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,27 @@
| .env file with the following name: "SP_MAIL_FROM_NAME"
|
*/
'mail_from_name' => env('SP_MAIL_FROM_NAME', 'Application')
];
'mail_from_name' => env('SP_MAIL_FROM_NAME', 'Application'),

/*
|--------------------------------------------------------------------------
| model
|--------------------------------------------------------------------------
|
| The model that can use simple-passport features
|
*/

'model' => \App\User::class,

/*
|--------------------------------------------------------------------------
| after_seconds
|--------------------------------------------------------------------------
|
| How many seconds before dispatch the jobs to send mails
|
*/

'after_seconds' => 10,
];
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto;">
<tr>
<td class="button-td button-td-primary" style="border-radius: 4px; background: #f5f5f5;">
<a class="button-a button-a-primary" href="{{ config('simple-passport.recover_url') . $user->password_token }}" style="background: #f5f5f5; border: 1px solid #000000; font-family: sans-serif; font-size: 15px; line-height: 15px; text-decoration: none; padding: 13px 17px; color: #000000; display: block; border-radius: 4px;">@lang('simple-passport::forgot-password.button')</a>
<a class="button-a button-a-primary" href="{{ config('simple-passport.recover_url') . $token }}" style="background: #f5f5f5; border: 1px solid #000000; font-family: sans-serif; font-size: 15px; line-height: 15px; text-decoration: none; padding: 13px 17px; color: #000000; display: block; border-radius: 4px;">@lang('simple-passport::forgot-password.button')</a>
</td>
</tr>
</table>
Expand Down
5 changes: 5 additions & 0 deletions front-end/src/app/authentication/recover/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ export const locale: Locale = {
'RECOVER': {
'TITLE': 'Recover your password',
'FIELDS': {
'EMAIL': 'Email address',
'PASSWORD': 'New password',
'PASSWORD_CONFIRMATION': 'Password confirmation'
},
'ERRORS': {
'EMAIL': {
'REQUIRED': 'The email address is required',
'VALID': 'Please enter a valid email address'
},
'PASSWORD': {
'REQUIRED': 'The password is required'
},
Expand Down
5 changes: 5 additions & 0 deletions front-end/src/app/authentication/recover/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ export const locale: Locale = {
'RECOVER': {
'TITLE': 'Récupère ton mot de passe',
'FIELDS': {
'EMAIL': 'Adresse email',
'PASSWORD': 'Nouveau mot de passe',
'PASSWORD_CONFIRMATION': 'Confirmation du mot de passe'
},
'ERRORS': {
'EMAIL': {
'REQUIRED': 'L\'adresse email est obligatiore',
'VALID': 'Veuillez entrer une adresse email valide'
},
'PASSWORD': {
'REQUIRED': 'Le mot de passe est obligatoire'
},
Expand Down
22 changes: 22 additions & 0 deletions front-end/src/app/authentication/recover/recover.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ <h1 class="display-3">{{ 'RECOVER.TITLE' | translate }}</h1>
<!-- Recover password form -->
<form [formGroup]="form" class="justify-content-center" (submit)="recover()">

<!-- Username field -->
<div class="input-group mb-2" [class.has-error]="form.get('username').dirty && form.get('username').invalid">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-user"></i></div>
</div>
<input type="email" formControlName="username" class="form-control" [placeholder]="'RECOVER.FIELDS.EMAIL' | translate">
</div>
<!-- ./Username field -->

<!-- Username field validations container -->
<div class="row" *ngIf="form.get('username').dirty && form.get('username').invalid">
<div class="col-12">
<div class="alert alert-danger alert-transparent-left" role="alert" *ngIf="form.get('username').dirty && form.controls['username'].hasError('required')">
{{ 'RECOVER.ERRORS.EMAIL.REQUIRED' | translate }}
</div>
<div class="alert alert-danger alert-transparent-left" role="alert" *ngIf="form.get('username').dirty && form.get('username').hasError('email')">
{{ 'RECOVER.ERRORS.EMAIL.VALID' | translate }}
</div>
</div>
</div>
<!-- ./Username field validations container -->

<!-- Password field -->
<div class="input-group mb-2" [class.has-error]="form.get('password').dirty && form.get('password').invalid">
<div class="input-group-prepend">
Expand Down
11 changes: 8 additions & 3 deletions front-end/src/app/authentication/recover/recover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class RecoverComponent implements OnInit, OnDestroy {
*/
private buildForm(): void {
this.form = this._fb.group({
username: [ '', [ Validators.required, Validators.email ] ],
password: [ '', Validators.required ],
password_confirmation: [ '', Validators.required ]
});
Expand All @@ -116,6 +117,7 @@ export class RecoverComponent implements OnInit, OnDestroy {
recover(): void {
this.loading = true;
this.authenticationService.recoverPassword({
email: this.form.get('username').value,
password: this.form.get('password').value,
password_confirmation: this.form.get('password_confirmation').value
}, this.token)
Expand All @@ -125,9 +127,12 @@ export class RecoverComponent implements OnInit, OnDestroy {
this._router.navigate([constants.auth_url]);
success('Success!', 'Your password is successfully recovered. Please login to your account using your new password.', this._toastr, this.translateService);
}, (err: any) => {
if (err.status === 403) {
JSON.parse(err._body).errors.forEach((e: string) => {
warning('Error!', e, this._toastr, this.translateService);
if (err.status === 422) {
const errors = JSON.parse(err._body).errors;
Object.keys(errors).forEach(key => {
errors[key].forEach(e => {
warning('Error!', e, this._toastr, this.translateService);
});
});
} else {
error('Error!', 'An internal error has occurred, please contact system administrator.', this._toastr, this.translateService);
Expand Down

0 comments on commit 9c884de

Please sign in to comment.