Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { IonicPage, NavController, NavParams, AlertController} from 'ionic-angular';
- import { RegisterPage } from '../register/register';
- import { FormBuilder, FormGroup } from '@angular/forms';
- import { Storage } from '@ionic/storage';
- import { Http } from '@angular/http';
- import 'rxjs/add/operator/map';
- import { TabsPage } from '../tabs/tabs';
- @IonicPage()
- @Component({
- selector: 'page-login',
- templateUrl: 'login.html',
- })
- export class LoginPage {
- credentialsForm: FormGroup;
- usernamee:string;
- passwordd:string;
- constructor(
- public navCtrl: NavController,
- public navParams: NavParams,
- public alertCtrl: AlertController,
- public http : http,
- private formBuilder: FormBuilder,
- private storage: Storage) {
- this.credentialsForm = this.formBuilder.group({
- password: [''],
- username: ['']
- });
- this.passwordd = "";
- this.usernamee = "";
- }
- ionViewDidLoad(){
- console.log('ionViewDidLoad LoginPage');
- }
- showAlert(){
- let alert = this.alertCtrl.create({
- title: 'Login Berhasil',
- subtitle: 'Yes, Login Sukses',
- buttons: ['OK']
- });
- alert.present();
- }
- showAlert2(){
- let alert = this.alertCtrl.create({
- title: 'Login Gagal',
- subtitle: 'No, Gagal',
- buttons: ['OK']
- });
- alert.present();
- }
- cekstorage(){
- console.log('Your Username is', this.credentialsForm.controls['username'].value)
- console.log('Your Password is', this.credentialsForm.controls['password'].value)
- this.storage.get('username').then((val) => {
- this.usernamee = val;
- console.log('Username di storage', val);
- });
- this.storage.get('password').then((val) => {
- this.passwordd = val;
- console.log('password di storage', val);
- });
- if (this.credentialsForm.controls['username'].value == this.usernamee && this.credentialsForm.controls['password'].value == this.passwordd)
- this.showAlert();
- else
- this.showAlert2();
- }
- gotoRegister(){
- this.navCtrl.push(RegisterPage);
- }
- doLogin()
- {
- let data = {
- username: btoa(this.username),
- password: btoa(this.password)
- };
- let url = 'http://lab.oo/index.php?/login/dologin';
- let dataJSON = JSON.stringify(data);
- this.http.post(url, dataJSON)
- .map(res => res.json())
- .subscribe(
- data => {
- if(data.status == 'true')
- {
- this.navCtrl.setRoot(TabsPage);
- console.log('login succes');
- }
- else
- {
- this.showAlert('Login Gagal, username atau password salah');
- console.log('login failed');
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement