105 Ionic Creator Sign Up API
.
105 Ionic Creator Sign Up API
This project develops a login and sign up apps that stores login details in the Cloud.
We will use Google Apps Script as the back end for this project.
1. Create Apps Script project
1. AppData.gs (Data Setup codes)
(you need to add objDB library)
/* uses library: objDB script id: 1o_O_ZkZm1GuTF5J1LYkfntUpiaT0sxDHyhZXL4fQma89mNIB65epbL6H */ /* 1-SETUP APP DATA Create spreadsheet file (app-data) in the same folder as app script file */ function setupAppData(){ var SCPID = ScriptApp.getScriptId(); var file = DriveApp.getFileById(SCPID); var folders = file.getParents(); while (folders.hasNext()){ FOLID=folders.next().getId(); } FOLDER = DriveApp.getFolderById(FOLID); var d = new Date(); var t = d.getTime(); var NEWSST = SpreadsheetApp.create("105-app-data-"+t); var TEMP = DriveApp.getFileById(NEWSST.getId()); FOLDER.addFile(TEMP); DriveApp.getRootFolder().removeFile(TEMP); var scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ scpid:SCPID, folid:FOLID, sstid:NEWSST.getId() }); /*record headers*/ /*n=name, g=gmail,hpw=hashedpassword, pc=pincode*/ var arrRecordTitles=["admins","users"]; var arrRecordHeaders=[ ["tid","timestamp","an","ae","salt","ahpw","apc","log"], ["tid","timestamp","un","ue","salt","uhpw","upc","log"] ]; for (i in arrRecordTitles){ var Sheet = NEWSST.getSheetByName(arrRecordTitles[i]); if (Sheet != null) { NEWSST.setActiveSheet(NEWSST.getSheetByName(arrRecordTitles[i])); NEWSST.deleteActiveSheet(); } NewSheet = NEWSST.insertSheet(); NewSheet.setName(arrRecordTitles[i]); NewSheet.appendRow(arrRecordHeaders[i]); NewSheet.getRange("A2:A").setNumberFormat(@STRING@); } } /* 2-INIT APP DATA Get the ScriptProperties values If empty, call setupApp() */ function initAppData(){ var SCRIPTPROP = PropertiesService.getScriptProperties(); var objProp=SCRIPTPROP.getProperties(); //if objProp is empty then call setupApp() if (Object.keys(objProp).length == 0){ setupAppData(); SCRIPTPROP = PropertiesService.getScriptProperties(); } //Logger.log(SCRIPTPROP.getProperties()); /* projectkey=MJMF2lqsgWV-I-dlyqJN6OrljYCrJdQKl */ var DB1 = objDB.open(SCRIPTPROP.getProperty("sstid")); return DB1; } /* 3-REMOVE APP DATA Get SSTID (if any) Send file to trash */ function delAppData(){ var SCRIPTPROP = PropertiesService.getScriptProperties(); var objProp=SCRIPTPROP.getProperties(); if (Object.keys(objProp).length != 0){ SSTID=SCRIPTPROP.getProperty("sstid")||; if (SSTID!=){ DriveApp.getFileById(SSTID).setTrashed(true); SCRIPTPROP.deleteAllProperties(); } } } |
2. Crypto.gs (Hash function)
eval(UrlFetchApp.fetch(https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js).getContentText()); function testCryptoJS() { var hash = CryptoJS.SHA256("Message"); /*alert(hash.toString(CryptoJS.enc.Base64));*/ Logger.log(hash.toString(CryptoJS.enc.Base64)); } |
3. Jsrsasign (JWT function)
var navigator = {}; var window = {}; eval(UrlFetchApp.fetch(https://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js).getContentText()); /*refer http://programming-steps.blogspot.my/2017/04/apps-script-and-json-web-token.html */ function tknMakeToken(objPayload,tpw){ var strToken=KJUR.jws.JWS.sign(null, {"alg":"HS256"}, objPayload, {"utf8": tpw}); return strToken; } function tknVerifyToken(strToken,tpw){ return KJUR.jws.JWS.verifyJWT(strToken, {"utf8": tpw}, {alg: ["HS256"]}); } function tknGetPayload(strToken){ var objPayload= KJUR.jws.JWS.readSafeJSONString(b64utoutf8(strToken.split(".")[1])); return objPayload; } function testTkn(){ var tpw=password; strToken=tknMakeToken({un:aba,ug:aba@gmail.com},tpw); Logger.log(strToken); isValid=tknVerifyToken(strToken,tpw); Logger.log(isValid); objPayload=tknGetPayload(strToken); Logger.log(JSON.stringify(objPayload));
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.