MOBILE-2253 login: Implement forgotten password
parent
0f087326d4
commit
166fafb4e7
|
@ -108,3 +108,7 @@ ion-icon.icon-accessory {
|
||||||
color: $item-icon-accessory-color;
|
color: $item-icon-accessory-color;
|
||||||
font-size: $item-icon-accessory-font-size;
|
font-size: $item-icon-accessory-font-size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mm-bold, .mm-bold .label {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<ion-header>
|
||||||
|
<ion-navbar>
|
||||||
|
<ion-title>{{ 'mm.login.passwordforgotten' | translate }}</ion-title>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
|
<ion-content>
|
||||||
|
<ion-item text-wrap>
|
||||||
|
{{ 'mm.login.passwordforgotteninstructions2' | translate }}
|
||||||
|
</ion-item>
|
||||||
|
<ion-card>
|
||||||
|
<form [formGroup]="myForm" (ngSubmit)="resetPassword()">
|
||||||
|
<ion-item-divider class="mm-bold" text-wrap color="light">
|
||||||
|
{{ 'mm.login.searchby' | translate }}
|
||||||
|
</ion-item-divider>
|
||||||
|
<div radio-group formControlName="field">
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>{{ 'mm.login.username' | translate }}</ion-label>
|
||||||
|
<ion-radio value="username"></ion-radio>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<ion-label>{{ 'mm.user.email' | translate }}</ion-label>
|
||||||
|
<ion-radio value="email"></ion-radio>
|
||||||
|
</ion-item>
|
||||||
|
</div>
|
||||||
|
<ion-item>
|
||||||
|
<ion-input type="text" name="value" placeholder="{{ 'mm.login.usernameoremail' | translate }}" formControlName="value" autocapitalize="none" autocorrect="off"></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item padding text-wrap>
|
||||||
|
<button ion-button block color="primary" [disabled]="!myForm.valid">{{ 'mm.courses.search' | translate }}</button>
|
||||||
|
</ion-item>
|
||||||
|
</form>
|
||||||
|
</ion-card>
|
||||||
|
</ion-content>
|
|
@ -0,0 +1,31 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { IonicPageModule } from 'ionic-angular';
|
||||||
|
import { CoreLoginForgottenPasswordPage } from './forgotten-password';
|
||||||
|
import { CoreLoginModule } from '../../login.module';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
CoreLoginForgottenPasswordPage
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
CoreLoginModule,
|
||||||
|
IonicPageModule.forChild(CoreLoginForgottenPasswordPage),
|
||||||
|
TranslateModule.forChild()
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class CoreLoginForgottenPasswordPageModule {}
|
|
@ -0,0 +1,6 @@
|
||||||
|
page-core-login-forgotten-password {
|
||||||
|
.content {
|
||||||
|
background: -webkit-radial-gradient(white, $gray-light);
|
||||||
|
background: radial-gradient(white, $gray-light);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { IonicPage, NavController, NavParams } from 'ionic-angular';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
|
||||||
|
import { CoreLoginHelperProvider } from '../../providers/helper';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page to recover a forgotten password.
|
||||||
|
*/
|
||||||
|
@IonicPage()
|
||||||
|
@Component({
|
||||||
|
selector: 'page-core-login-forgotten-password',
|
||||||
|
templateUrl: 'forgotten-password.html',
|
||||||
|
})
|
||||||
|
export class CoreLoginForgottenPasswordPage {
|
||||||
|
myForm: FormGroup;
|
||||||
|
siteUrl: string;
|
||||||
|
|
||||||
|
constructor(private navCtrl: NavController, navParams: NavParams, fb: FormBuilder, private translate: TranslateService,
|
||||||
|
private loginHelper: CoreLoginHelperProvider, private domUtils: CoreDomUtilsProvider) {
|
||||||
|
|
||||||
|
this.siteUrl = navParams.get('siteUrl');
|
||||||
|
this.myForm = fb.group({
|
||||||
|
'field': ['username', Validators.required],
|
||||||
|
'value': [navParams.get('username') || '', Validators.required]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to reset the password.
|
||||||
|
*/
|
||||||
|
resetPassword() : void {
|
||||||
|
let field = this.myForm.value.field,
|
||||||
|
value = this.myForm.value.value;
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
this.domUtils.showErrorModal('mm.login.usernameoremail', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let modal = this.domUtils.showModalLoading('mm.core.sending', true),
|
||||||
|
isMail = field == 'email';
|
||||||
|
|
||||||
|
this.loginHelper.requestPasswordReset(this.siteUrl, isMail ? '' : value, isMail ? value : '').then((response) => {
|
||||||
|
if (response.status == 'dataerror') {
|
||||||
|
// Error in the data sent.
|
||||||
|
this.showError(isMail, response.warnings);
|
||||||
|
} else if (response.status == 'emailpasswordconfirmnotsent' || response.status == 'emailpasswordconfirmnoemail') {
|
||||||
|
// Error, not found.
|
||||||
|
this.domUtils.showErrorModal(response.notice);
|
||||||
|
} else {
|
||||||
|
// Success.
|
||||||
|
this.domUtils.showAlert(this.translate.instant('mm.core.success'), response.notice);
|
||||||
|
this.navCtrl.pop();
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
this.domUtils.showErrorModal(error.error);
|
||||||
|
}).finally(() => {
|
||||||
|
modal.dismiss();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Show an error from the warnings.
|
||||||
|
protected showError(isMail: boolean, warnings: any[]) : void {
|
||||||
|
for (let i = 0; i < warnings.length; i++) {
|
||||||
|
let warning = warnings[i];
|
||||||
|
if ((warning.item == 'email' && isMail) || (warning.item == 'username' && !isMail)) {
|
||||||
|
this.domUtils.showErrorModal(warning.message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue