Skip to content

Commit d3d2be9

Browse files
committed
Ep.4-Profile tab
1 parent c9829b8 commit d3d2be9

File tree

7 files changed

+171
-20
lines changed

7 files changed

+171
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
},
3737
"devDependencies": {
3838
"@ionic/app-scripts": "1.3.7",
39-
"@ionic/cli-plugin-cordova": "1.3.0",
40-
"@ionic/cli-plugin-ionic-angular": "1.3.0",
39+
"@ionic/cli-plugin-cordova": "1.4.0",
40+
"@ionic/cli-plugin-ionic-angular": "1.3.1",
4141
"typescript": "2.3.3"
4242
},
4343
"description": "An Ionic project"

src/app/app.firebaseconfig.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export var config = {
2-
apiKey: <apiKey>,
3-
authDomain: <yourauthDomain>,
4-
databaseURL: <yourdatabaseURL>,
5-
projectId: <yourprojectId>,
6-
storageBucket: <yourstoragebucket>,
7-
messagingSenderId: <yoursenderIdhere>
2+
apiKey: "AIzaSyA9_FQFy-4eF31iznvfadBeR2Y3xJ4SfJ0",
3+
authDomain: "ionic3chat-5e5cc.firebaseapp.com",
4+
databaseURL: "https://ionic3chat-5e5cc.firebaseio.com",
5+
projectId: "ionic3chat-5e5cc",
6+
storageBucket: "ionic3chat-5e5cc.appspot.com",
7+
messagingSenderId: "480109185305"
88
};

src/pages/passwordreset/passwordreset.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export class PasswordresetPage {
3131
alert.setTitle('Email Sent');
3232
alert.setSubTitle('Please follow the instructions in the email to reset your password');
3333
}
34-
else {
35-
alert.setTitle('Failed');
36-
}
34+
}).catch((err) => {
35+
alert.setTitle('Failed');
36+
alert.setSubTitle(err);
3737
})
3838
}
3939

src/pages/profile/profile.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
</ion-header>
1414

1515

16-
<ion-content padding>
17-
16+
<ion-content>
17+
<div class="profile-image" (click)="editimage()">
18+
<img src="{{avatar}}">
19+
</div>
20+
<div>
21+
<h2 (click)="editname()">{{displayName}}</h2>
22+
</div>
23+
<div>
24+
Tap on your pic or nick name to change it.
25+
</div>
26+
<div class="spacer" style="height: 10px;"></div>
27+
<div>
28+
<button ion-button round outline color="danger" (click)="logout()">Logout</button>
29+
</div>
1830
</ion-content>

src/pages/profile/profile.scss

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
page-profile {
2-
2+
.profile-image{
3+
img{
4+
height: 200px;
5+
width: 200px;
6+
border-radius:50%;
7+
border: 4px solid rgba(255,255,255,0.4);
8+
-webkit-box-shadow: 0px 0px 142px -37px rgba(0,0,0,0.75);
9+
-moz-box-shadow: 0px 0px 142px -37px rgba(0,0,0,0.75);
10+
box-shadow: 0px 0px 142px -37px rgba(0,0,0,0.75);
11+
}
12+
}
13+
.scroll-content {
14+
align-content: center;
15+
display: flex;
16+
flex-direction: column;
17+
justify-content: center;
18+
text-align: center;
19+
}
320
}

src/pages/profile/profile.ts

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Component } from '@angular/core';
2-
import { IonicPage, NavController, NavParams } from 'ionic-angular';
3-
1+
import { Component, NgZone } from '@angular/core';
2+
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
3+
import { ImghandlerProvider } from '../../providers/imghandler/imghandler';
4+
import { UserProvider } from '../../providers/user/user';
5+
import firebase from 'firebase';
46
/**
57
* Generated class for the ProfilePage page.
68
*
@@ -13,12 +15,99 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
1315
templateUrl: 'profile.html',
1416
})
1517
export class ProfilePage {
18+
avatar: string;
19+
displayName: string;
20+
constructor(public navCtrl: NavController, public navParams: NavParams,
21+
public userservice: UserProvider, public zone: NgZone, public alertCtrl: AlertController,
22+
public imghandler: ImghandlerProvider) {
23+
}
24+
25+
ionViewWillEnter() {
26+
this.loaduserdetails();
27+
}
1628

17-
constructor(public navCtrl: NavController, public navParams: NavParams) {
29+
loaduserdetails() {
30+
this.userservice.getuserdetails().then((res: any) => {
31+
this.displayName = res.displayName;
32+
this.zone.run(() => {
33+
this.avatar = res.photoURL;
34+
})
35+
})
1836
}
1937

20-
ionViewDidLoad() {
21-
console.log('ionViewDidLoad ProfilePage');
38+
editimage() {
39+
let statusalert = this.alertCtrl.create({
40+
buttons: ['okay']
41+
});
42+
this.imghandler.uploadimage().then((url: any) => {
43+
this.userservice.updateimage(url).then((res: any) => {
44+
if (res.success) {
45+
statusalert.setTitle('Updated');
46+
statusalert.setSubTitle('Your profile pic has been changed successfully!!');
47+
statusalert.present();
48+
this.zone.run(() => {
49+
this.avatar = url;
50+
})
51+
}
52+
}).catch((err) => {
53+
statusalert.setTitle('Failed');
54+
statusalert.setSubTitle('Your profile pic was not changed');
55+
statusalert.present();
56+
})
57+
})
2258
}
2359

60+
editname() {
61+
let statusalert = this.alertCtrl.create({
62+
buttons: ['okay']
63+
});
64+
let alert = this.alertCtrl.create({
65+
title: 'Edit Nickname',
66+
inputs: [{
67+
name: 'nickname',
68+
placeholder: 'Nickname'
69+
}],
70+
buttons: [{
71+
text: 'Cancel',
72+
role: 'cancel',
73+
handler: data => {
74+
75+
}
76+
},
77+
{
78+
text: 'Edit',
79+
handler: data => {
80+
if (data.nickname) {
81+
this.userservice.updatedisplayname(data.nickname).then((res: any) => {
82+
if (res.success) {
83+
statusalert.setTitle('Updated');
84+
statusalert.setSubTitle('Your nickname has been changed successfully!!');
85+
statusalert.present();
86+
this.zone.run(() => {
87+
this.displayName = data.nickname;
88+
})
89+
}
90+
91+
else {
92+
statusalert.setTitle('Failed');
93+
statusalert.setSubTitle('Your nickname was not changed');
94+
statusalert.present();
95+
}
96+
97+
})
98+
}
99+
}
100+
101+
}]
102+
});
103+
alert.present();
104+
}
105+
106+
logout() {
107+
firebase.auth().signOut().then(() => {
108+
this.navCtrl.parent.parent.setRoot('LoginPage');
109+
})
110+
}
111+
112+
24113
}

src/providers/user/user.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,37 @@ export class UserProvider {
103103
return promise;
104104
}
105105

106+
getuserdetails() {
107+
var promise = new Promise((resolve, reject) => {
108+
this.firedata.child(firebase.auth().currentUser.uid).once('value', (snapshot) => {
109+
resolve(snapshot.val());
110+
}).catch((err) => {
111+
reject(err);
112+
})
113+
})
114+
return promise;
115+
}
116+
117+
updatedisplayname(newname) {
118+
var promise = new Promise((resolve, reject) => {
119+
this.afireauth.auth.currentUser.updateProfile({
120+
displayName: newname,
121+
photoURL: this.afireauth.auth.currentUser.photoURL
122+
}).then(() => {
123+
this.firedata.child(firebase.auth().currentUser.uid).update({
124+
displayName: newname,
125+
photoURL: this.afireauth.auth.currentUser.photoURL,
126+
uid: this.afireauth.auth.currentUser.uid
127+
}).then(() => {
128+
resolve({ success: true });
129+
}).catch((err) => {
130+
reject(err);
131+
})
132+
}).catch((err) => {
133+
reject(err);
134+
})
135+
})
136+
return promise;
137+
}
138+
106139
}

0 commit comments

Comments
 (0)