diff --git a/src/app/app.scss b/src/app/app.scss index 8442bfc77..42b840fb9 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -108,3 +108,7 @@ ion-icon.icon-accessory { color: $item-icon-accessory-color; font-size: $item-icon-accessory-font-size; } + +.mm-bold, .mm-bold .label { + font-weight: bold; +} diff --git a/src/core/login/pages/forgotten-password/forgotten-password.html b/src/core/login/pages/forgotten-password/forgotten-password.html new file mode 100644 index 000000000..29cb8052b --- /dev/null +++ b/src/core/login/pages/forgotten-password/forgotten-password.html @@ -0,0 +1,33 @@ + + + {{ 'mm.login.passwordforgotten' | translate }} + + + + + {{ 'mm.login.passwordforgotteninstructions2' | translate }} + + + + + {{ 'mm.login.searchby' | translate }} + + + + {{ 'mm.login.username' | translate }} + + + + {{ 'mm.user.email' | translate }} + + + + + + + + {{ 'mm.courses.search' | translate }} + + + + diff --git a/src/core/login/pages/forgotten-password/forgotten-password.module.ts b/src/core/login/pages/forgotten-password/forgotten-password.module.ts new file mode 100644 index 000000000..9cbc9148d --- /dev/null +++ b/src/core/login/pages/forgotten-password/forgotten-password.module.ts @@ -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 {} diff --git a/src/core/login/pages/forgotten-password/forgotten-password.scss b/src/core/login/pages/forgotten-password/forgotten-password.scss new file mode 100644 index 000000000..ed3dcd36c --- /dev/null +++ b/src/core/login/pages/forgotten-password/forgotten-password.scss @@ -0,0 +1,6 @@ +page-core-login-forgotten-password { + .content { + background: -webkit-radial-gradient(white, $gray-light); + background: radial-gradient(white, $gray-light); + } +} diff --git a/src/core/login/pages/forgotten-password/forgotten-password.ts b/src/core/login/pages/forgotten-password/forgotten-password.ts new file mode 100644 index 000000000..f10f05f77 --- /dev/null +++ b/src/core/login/pages/forgotten-password/forgotten-password.ts @@ -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; + } + } + } +}