diff --git a/config.xml b/config.xml index 3c9264f..a486624 100644 --- a/config.xml +++ b/config.xml @@ -1,8 +1,8 @@ - - MyApp - An awesome Ionic/Cordova app. - Ionic Framework Team + + Passy + The mobile App for the Passy Password Manager + Passy Team diff --git a/ionic.config.json b/ionic.config.json index 2bc8f0c..3f2c0d0 100644 --- a/ionic.config.json +++ b/ionic.config.json @@ -1,5 +1,5 @@ { - "name": "mynewapp", + "name": "Passy", "app_id": "", "type": "ionic-angular" } diff --git a/package.json b/package.json index 6806326..7daf756 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "mynewapp", + "name": "passy", "version": "0.0.1", - "author": "Ionic Framework", - "homepage": "http://ionicframework.com/", + "author": "Liz3", + "homepage": "https://passy.pw", "private": true, "scripts": { "clean": "ionic-app-scripts clean", @@ -49,7 +49,7 @@ "@ionic/cli-plugin-ionic-angular": "1.3.0", "typescript": "2.3.3" }, - "description": "An Ionic project", + "description": "The mobile App for the Passy Password Manager", "cordova": { "plugins": { "cordova-plugin-http": {}, diff --git a/resources/icon.png b/resources/icon.png index bee7766..da0a825 100644 Binary files a/resources/icon.png and b/resources/icon.png differ diff --git a/resources/splash.png b/resources/splash.png index 028da91..9c1edf0 100644 Binary files a/resources/splash.png and b/resources/splash.png differ diff --git a/src/app/Passy.ts b/src/app/Passy.ts index 10f14d5..89593c9 100644 --- a/src/app/Passy.ts +++ b/src/app/Passy.ts @@ -1,148 +1,261 @@ import {Http, Headers, RequestOptions} from "@angular/http"; -import {MyApp} from "./app.component"; +import {loginScreen, popAlert} from "../pages/tabs/tabs"; export var passwords = []; +export var archived = []; export var loggedIn = false; export class Passy { - accessToken; - public loggedIn = false; - private _baseURL = "https://dev.liz3.net/passy-api/index.php"; + accessToken; + public loggedIn = false; + private _baseURL = "https://dev.liz3.net/passy-api/index.php"; - constructor(private app:MyApp) { + constructor() { - } + } + + private request(http: Http, vals, callback) { + + let opt: RequestOptions + let myHeaders: Headers = new Headers + myHeaders.set('Content-type', 'application/x-www-form-urlencoded'); + opt = new RequestOptions({ + headers: myHeaders + }); - private request(http: Http, vals, callback) { + http.post(this._baseURL, this.buildRequestString(vals), opt).subscribe(response => { + callback(response); + }) + + + } - let opt: RequestOptions - let myHeaders: Headers = new Headers - myHeaders.set('Content-type', 'application/x-www-form-urlencoded'); - opt = new RequestOptions({ - headers: myHeaders - }); + public archive(http, id, callback) { - http.post(this._baseURL, this.buildRequestString(vals), opt).subscribe(response => { - callback(response); - }) + const me = this; + this.request(http, [{name: "a", value: "password/archive"}, {name: "id", value: id}, { + name: "access_token", + value: this.accessToken + }], function (response) { - } + const json = JSON.parse(response.text()); - private buildRequestString(data: any[]) { + if (json.success) { + me.fetchPasswords(http); + } + callback(json); + }); - let response = ""; - for (let i = 0; i != data.length; i++) { - const current = data[i]; - if (response != "") response += "&"; - response += encodeURIComponent(current.name) + "=" + encodeURIComponent(current.value); } - return response; - } - public addPassword(http:Http, username, password, description, callback) { + private buildRequestString(data: any[]) { - const data = [{name: "a", value: "password/create"}, - { name: "access_token", value: this.accessToken}, - {name: "username", value: username}, {name: "password", value: password}, {name: "description", value: description}]; + let response = ""; + for (let i = 0; i != data.length; i++) { + const current = data[i]; + if (response != "") response += "&"; + response += encodeURIComponent(current.name) + "=" + encodeURIComponent(current.value); + } + return response; + } + + public addPassword(http: Http, username, password, description, callback) { - const me = this; - this.request(http, data, function (response) { + const data = [{name: "a", value: "password/create"}, + {name: "access_token", value: this.accessToken}, + {name: "username", value: username}, {name: "password", value: password}, { + name: "description", + value: description + }]; - const json = JSON.parse(response.text()); - if(json.success) { - me.fetchPasswords(http); - } - callback(json); - }); + const me = this; + this.request(http, data, function (response) { - } + const json = JSON.parse(response.text()); + if (json.success) { + me.fetchPasswords(http); + } + callback(json); + }); + + } - public tryLogin(name: string, pass: string, http: Http, callBack){ + public tryLogin(name: string, pass: string, http: Http, callBack) { - if (this.loggedIn) return; + if (this.loggedIn) return; - if (name != "" && pass != "") { + if (name != "" && pass != "") { - const me = this; - this.request(http, [{name: "a", value: "user/login"}, - {name: "username", value: name}, {name: "password", value: pass}], function (response) { + const me = this; + this.request(http, [{name: "a", value: "user/login"}, + {name: "username", value: name}, {name: "password", value: pass}], function (response) { - console.log(response) - const data = JSON.parse(response.text()); + console.log(response) + const data = JSON.parse(response.text()); - if (data.success) { - me.accessToken = data.token[0]; + if (data.success) { + me.accessToken = data.token[0]; - me.fetchPasswords(http); - loggedIn = true; - callBack(true); + me.fetchPasswords(http); + loggedIn = true; + callBack(true); + + const timer = setInterval(function () { + me.request(http, [{name: "access_token", value: me.accessToken}, {name: "a", value: "status"}], function (response) { + + const json = JSON.parse(response.text()); + if(!json.data.logged_in) { + passwords = []; + archived = []; + me.accessToken = ""; + loginScreen() + clearInterval(timer); + } + + }) + + }, 2000); + } else { + popAlert("Failed", "Failed to login"); + } + + }); } - }); + callBack(false); + } + + public getPassword(id, http: Http, callback) { + if (!loggedIn) return "Error"; + + this.request(http, [ + {name: "a", value: "password/query"}, {name: "id", value: id}, + { + name: "access_token", + value: this.accessToken + } + ], function (response) { + + const json = JSON.parse(response.text()); + callback(json.data.password); + + }); + } + + public editPassword(id, username, password, description, http, callback) { + + const me = this; + const data = [{name: "id", value: id}, + {name: "a", value: "password/edit"}, + {name: "username", value: username}, + {name: "password", value: password}, + {name: "description", value: description}, + {name: "access_token", value: this.accessToken}]; + + this.request(http, data, function (response) { + + const json = JSON.parse(response.text()); + if (json.success) { + me.fetchPasswords(http); + } + callback(json); + + + }); } - callBack(false); - } + public restorePass(http, id, callback) { + + const data = [{name: "a", value: "password/restore"}, {name: "id", value: id}, { + name: "access_token", + value: this.accessToken + }]; + const me = this; - public getPassword(id, http:Http, callback) { - if(!loggedIn) return "Error"; + this.request(http, data, function (response) { + if (response.success) { + me.fetchPasswords(http); + } + callback(JSON.parse(response.text())); + }); - this.request(http, [ - {name: "a", value: "password/query"},{name: "id", value: id}, - { name: "access_token", - value: this.accessToken - } - ], function (response) { - const json = JSON.parse(response.text()); - callback(json.data.password); + } - }); - } - private fetchPasswords(http: Http) { + public delPass(http, id, callback) { - this.request(http, [{name: "a", value: "password/queryAll"}, { - name: "access_token", - value: this.accessToken - }], function (response) { + const data = [{name: "a", value: "password/delete"}, {name: "id", value: id}, { + name: "access_token", + value: this.accessToken + }]; + const me = this; - const json = JSON.parse(response.text()); + this.request(http, data, function (response) { + if (response.success) { + me.fetchPasswords(http); + } + callback(JSON.parse(response.text())); + }); - passwords = json.data; - }); + } + + public fetchPasswords(http: Http) { + this.request(http, [{name: "a", value: "password/queryAll"}, { + name: "access_token", + value: this.accessToken + }], function (response) { - } + const json = JSON.parse(response.text()); + + const fetched = []; + const archive = []; + for (let i = 0; i != json.data.length; i++) { + const current = json.data[i]; + + if (current.archived) { + archive.push(current); + continue; + } + fetched.push(current); + } + archived = archive; + passwords = fetched; + + }); + + + } } export class Password { - private _id; - private _description; - private _username; + private _id; + private _description; + private _username; - constructor(id, description, username) { - this._id = id; - this._description = description; - this._username = username; - } + constructor(id, description, username) { + this._id = id; + this._description = description; + this._username = username; + } - get id() { - return this._id; - } + get id() { + return this._id; + } - get description() { - return this._description; - } + get description() { + return this._description; + } - get username() { - return this._username; - } + get username() { + return this._username; + } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 74be3e0..e3a0894 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -13,7 +13,7 @@ import {HomePage} from "../pages/home/home"; }) export class MyApp { rootPage:any = TabsPage; - public passy = new Passy(this); + public passy = new Passy(); constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { platform.ready().then(() => { passy = this.passy; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5e93a4f..d9d76b1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,7 @@ import {LoginPage} from "../pages/login/LoginPage"; import {PassShow} from "../pages/pass-show/pass-show"; import {NewPassPage} from "../pages/new-password/new-pass"; import {EditPassPage} from "../pages/edit-password/edit-pass"; +import {ArchivePage} from "../pages/archived/archive"; @NgModule({ declarations: [ @@ -23,6 +24,7 @@ import {EditPassPage} from "../pages/edit-password/edit-pass"; PassShow, NewPassPage, EditPassPage, + ArchivePage, ], imports: [ @@ -40,6 +42,7 @@ import {EditPassPage} from "../pages/edit-password/edit-pass"; PassShow, NewPassPage, EditPassPage, + ArchivePage, ], providers: [ StatusBar, diff --git a/src/pages/archived/archive.html b/src/pages/archived/archive.html new file mode 100644 index 0000000..e2855b5 --- /dev/null +++ b/src/pages/archived/archive.html @@ -0,0 +1,27 @@ + + + Archive + + + + + + + + + {{current.username || "None"}} + + + +

{{current.description || "None"}}

+
+ + + +
+ +
+ +
diff --git a/src/pages/archived/archive.scss b/src/pages/archived/archive.scss new file mode 100644 index 0000000..d4cc8fc --- /dev/null +++ b/src/pages/archived/archive.scss @@ -0,0 +1,3 @@ +page-home { + +} diff --git a/src/pages/archived/archive.ts b/src/pages/archived/archive.ts new file mode 100644 index 0000000..6a2aec6 --- /dev/null +++ b/src/pages/archived/archive.ts @@ -0,0 +1,75 @@ +import { Component } from '@angular/core'; +import {ActionSheetController, ModalController, NavController, PopoverController, Tabs} from 'ionic-angular'; +import {Http} from "@angular/http"; +import {archived} from "../../app/Passy"; +import {passy} from "../../app/app.component"; +import {PassShow} from "../pass-show/pass-show"; +import {NewPassPage} from "../new-password/new-pass"; +import {EditPassPage} from "../edit-password/edit-pass"; + + + +@Component({ + selector: 'page-home', + templateUrl: 'archive.html' +}) +export class ArchivePage { + + get passwords() { + return archived; + } + + constructor(public modalCtrl: ModalController, + public popoverCtrl: PopoverController, + public navCtrl: NavController, + private http: Http, + public actionSheetCtrl: ActionSheetController) { + + + + } + addPass() { + + let popover = this.modalCtrl.create(NewPassPage); + popover.present({ + }); + + } + public more(value) { + + const me = this; + let actionSheet = this.actionSheetCtrl.create({ + title: 'Edit or achive this password', + buttons: [ + { + text: 'Restore', + handler: () => { + const id = value.password_id; + passy.restorePass(me.http, id, function (data) { + passy.fetchPasswords(me.http); + }) + + } + },{ + text: 'Delete', + handler: () => { + passy.delPass(me.http, value.password_id, function (data) { + passy.fetchPasswords(me.http); + + }) + } + },{ + text: 'Cancel', + role: 'cancel', + handler: () => { + + + } + } + ] + }); + actionSheet.present(); + } + + +} diff --git a/src/pages/edit-password/edit-pass.html b/src/pages/edit-password/edit-pass.html index 3d11dd9..95fb36a 100644 --- a/src/pages/edit-password/edit-pass.html +++ b/src/pages/edit-password/edit-pass.html @@ -8,7 +8,7 @@ Password - + Description diff --git a/src/pages/edit-password/edit-pass.ts b/src/pages/edit-password/edit-pass.ts index 76f629b..f2ad100 100644 --- a/src/pages/edit-password/edit-pass.ts +++ b/src/pages/edit-password/edit-pass.ts @@ -1,7 +1,7 @@ import {Component} from "@angular/core"; import {Http} from "@angular/http"; import {passy} from "../../app/app.component"; -import {ViewController} from "ionic-angular"; +import {NavParams, ViewController} from "ionic-angular"; @Component({ selector: 'new-pass', templateUrl: 'edit-pass.html' @@ -9,12 +9,17 @@ import {ViewController} from "ionic-angular"; export class EditPassPage { + private id; private username; private password; private description; - constructor(public viewCtrl: ViewController,public http:Http) { + constructor(public viewCtrl: ViewController,public http:Http, private navParams: NavParams) { + this.id = navParams.data.password.data.password_id; + this.username = navParams.data.password.data.username; + this.password = navParams.data.password.pass; + this.description = navParams.data.password.data.description; } @@ -22,7 +27,7 @@ export class EditPassPage { const me = this; - passy.addPassword(this.http, this.username, this.password, this.description, function (data) { + passy.editPassword(this.id,this.username,this.password, this.description, this.http, function (data) { if(!data.success) { diff --git a/src/pages/home/home.ts b/src/pages/home/home.ts index 472db90..902a19a 100644 --- a/src/pages/home/home.ts +++ b/src/pages/home/home.ts @@ -5,6 +5,7 @@ import {passwords} from "../../app/Passy"; import {passy} from "../../app/app.component"; import {PassShow} from "../pass-show/pass-show"; import {NewPassPage} from "../new-password/new-pass"; +import {EditPassPage} from "../edit-password/edit-pass"; @@ -36,26 +37,36 @@ export class HomePage { } public more(value) { - console.log(value); + const me = this; let actionSheet = this.actionSheetCtrl.create({ title: 'Edit or achive this password', buttons: [ { text: 'Edit', handler: () => { - console.log("weo"); + const id = value.password_id; + passy.getPassword(id, this.http, function (password) { + let popover = me.modalCtrl.create(EditPassPage, { + password: {data: value, pass: password} + }); + popover.present({ + }); + }); + } },{ text: 'Delete', handler: () => { - console.log("weo"); + passy.archive(me.http, value.password_id, function (data) { + + }) } },{ text: 'Cancel', role: 'cancel', handler: () => { - console.log("weo"); + } } @@ -68,7 +79,6 @@ export class HomePage { const me = this; passy.getPassword(id, this.http, function (pass) { - console.log(pass); let popover = me.popoverCtrl.create(PassShow, { passInf: password, password: pass diff --git a/src/pages/login/login-page.html b/src/pages/login/login-page.html index cf3a9ee..75b4dce 100644 --- a/src/pages/login/login-page.html +++ b/src/pages/login/login-page.html @@ -1,18 +1,29 @@ - + - - Username - - + + Login to Passy + - - Password - - + + + + + Username + + + + + Password + + + + +
+ +
+
+ +
-
-
- -
diff --git a/src/pages/tabs/tabs.ts b/src/pages/tabs/tabs.ts index dd4d646..d00e189 100644 --- a/src/pages/tabs/tabs.ts +++ b/src/pages/tabs/tabs.ts @@ -1,22 +1,41 @@ import { Component } from '@angular/core'; import {LoginPage} from '../login/LoginPage'; import { HomePage } from '../home/home'; -import {ModalController, NavController, PopoverController} from "ionic-angular"; +import {ModalController, NavController, PopoverController, AlertController} from "ionic-angular"; +import {ArchivePage} from "../archived/archive"; +export var alertController = null; +export var modalController = null; @Component({ templateUrl: 'tabs.html' }) export class TabsPage { - tabs = [{title: "Passwords", site: HomePage, icon: "home"}]; + tabs = [{title: "Passwords", site: HomePage, icon: "home"}, + {title: "Archive", site: ArchivePage, icon: "home"}]; - constructor(public modalCtrl: ModalController) { - - let popover = this.modalCtrl.create(LoginPage) + constructor(public modalCtrl: ModalController, public alertCtrl: AlertController) { + alertController = alertCtrl; + modalController = modalCtrl; + let popover = this.modalCtrl.create(LoginPage); popover.present({ }); } } +export function loginScreen() { + let popover = modalController.create(LoginPage); + popover.present({ + }); +} +export function popAlert(title, msg) { + + let alert = alertController.create({ + title: title, + subTitle: msg, + buttons: ['OK'] + }); + alert.present(); +} \ No newline at end of file