Guest User

Untitled

a guest
Oct 31st, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { NavController, ModalController, LoadingController, AlertController, ToastController } from 'ionic-angular';
  3. import { RegisterPage } from '../register/register';
  4. import { HomePage } from '../home/home';
  5. import { UsersService } from '../../providers/users-service';
  6.  
  7.  
  8. /*
  9. Generated class for the Login page.
  10.  
  11. See http://ionicframework.com/docs/v2/components/#navigation for more info on
  12. Ionic pages and navigation.
  13. */
  14. @Component({
  15. selector: 'page-login',
  16. templateUrl: 'login.html',
  17. providers: [UsersService]
  18. })
  19. export class LoginPage {
  20.  
  21. public emailField: any;
  22. public passwordField: any;
  23. private users = [];
  24. private usersList : any;
  25.  
  26. constructor(private alertCtrl: AlertController, private loadingCtrl: LoadingController, private modalCtrl: ModalController, public navCtrl: NavController, private usersService: UsersService, private toastCtrl: ToastController) {
  27.  
  28. this.emailField="bokeefe08@gmail.com";
  29.  
  30. this.listOurUsers();
  31.  
  32. }
  33.  
  34. signUpUser() {
  35.  
  36. this.usersService.signUpUser(this.emailField, this.passwordField).then(authData => {
  37. //successful
  38. this.navCtrl.setRoot(HomePage);
  39. }, error => {
  40. //alert("Error logging in:"+ error.message);
  41. let alert = this.alertCtrl.create({
  42. title: 'Error logging in',
  43. subTitle: error.message,
  44. buttons: ['OK']
  45. });
  46. alert.present();
  47.  
  48. });
  49.  
  50. let loader = this.loadingCtrl.create({
  51. dismissOnPageChange: true,
  52.  
  53. });
  54.  
  55. loader.present();
  56.  
  57. }
  58.  
  59. listOurUsers() {
  60. this.usersService.loadUser(10)
  61. .then(data => {
  62. this.usersList = data;
  63. })
  64.  
  65. }
  66.  
  67. submitLogin (){
  68. this.usersService.loginUser(this.emailField, this.passwordField).then(authData => {
  69. //successful
  70. this.navCtrl.setRoot(HomePage);
  71. }, error => {
  72. //alert("Error logging in:"+ error.message);
  73.  
  74. let alert = this.alertCtrl.create({
  75. title: 'New Friend!',
  76. subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
  77. buttons: ['OK']
  78. });
  79. alert.present();
  80.  
  81. });
  82.  
  83. }
  84.  
  85.  
  86. submitRegister (){
  87.  
  88. let registerModal = this.modalCtrl.create(RegisterPage);
  89. registerModal.present();
  90.  
  91. }
  92.  
  93. showForgotPassword() {
  94.  
  95. //
  96.  
  97. let prompt = this.alertCtrl.create({
  98. title: 'Enter Your Email',
  99. message: "A new password will be sent to your email",
  100. inputs: [
  101. {
  102. name: 'recoverEmail',
  103. placeholder: 'you@example.com'
  104. },
  105. ],
  106. buttons: [
  107. {
  108. text: 'Cancel',
  109. handler: data => {
  110. console.log('Cancel clicked');
  111. }
  112. },
  113. {
  114. text: 'Submit',
  115. handler: data => {
  116.  
  117. //add preloader
  118. let loading = this.loadingCtrl.create({
  119. dismissOnPageChange: true,
  120. content: 'Reseting your password..'
  121. });
  122.  
  123. loading.present();
  124.  
  125. //call userservice
  126. this.usersService.forgotUserPassword(data.recoverEmail).then(() => {
  127.  
  128. //add toast
  129. loading.dismiss().then(() => {
  130. //show pop-up
  131. let alert = this.alertCtrl.create({
  132. title: 'Password Reset Successful',
  133. subTitle: 'Please check your email',
  134. buttons: ['OK']
  135. });
  136. alert.present();
  137.  
  138.  
  139. })
  140.  
  141.  
  142.  
  143. }, error => {
  144. //show pop-up
  145. loading.dismiss().then(() => {
  146. let alert = this.alertCtrl.create({
  147. title: 'Error resetting password',
  148. subTitle: error.message,
  149. buttons: ['OK']
  150. });
  151. alert.present();
  152. })
  153.  
  154. });
  155.  
  156. }
  157. }
  158. ]
  159. });
  160. prompt.present();
  161.  
  162.  
  163.  
  164.  
  165. }
  166.  
  167.  
  168.  
  169. googleSignIn(){
  170.  
  171. this.usersService.googleSignInUser().then(()=>{
  172. //success, redirect
  173. let toast = this.toastCtrl.create({
  174. message: 'User account created successfully...',
  175. duration: 3000
  176. });
  177. toast.present();
  178.  
  179. });
  180.  
  181. }
  182.  
  183.  
  184.  
  185.  
  186. ionViewDidLoad() {
  187. console.log('Hello Login Page');
  188. }
  189.  
  190. }
Add Comment
Please, Sign In to add comment