MCPcopy Create free account
hub / github.com/Milkyroad/SCiPNET / loginProcess

Function loginProcess

public/src/js/login.js:16–111  ·  view source on GitHub ↗
(val)

Source from the content-addressed store, hash-verified

14
15//login user through firebase auth
16export const loginProcess = (val) => {
17 if (val.trim().toLowerCase() == "quit") {
18 emailLog = "";
19 passLog = "";
20 keyLog = "";
21 btnShow()
22 appendNormal("Login process exited")
23 loginState = 0
24 } else {
25 if (loginState == 1) {
26 cmdHide()
27 firebase.auth().fetchSignInMethodsForEmail(val)
28 .then((signInMethods) => {
29 if (signInMethods.length) {
30 emailLog = val
31 appendNormal(`The email address you have entered is:<span class='highlight'> ${val}</span><br><hr><small style='opacity:0.7'>Enter "Y" to continue or "N" to re-enter your email. You can exit the login process at any time by entering "Quit".</small>`)
32 loginState = 2
33 } else {
34 appendError(`THIS EMAIL IS NOT REGISTERED. PLEASE ENTER ANOTHER EMAIL OR YOU CAN CHOOSE TO REGISTER <br><hr><small style='opacity:0.7'>If you wish to register, enter "Quit" to exit the login process. After that, enter "Register" to register.</small>`)
35 loginState = 1
36 }
37 cmdShow()
38 })
39 .catch((error) => {
40 cmdShow()
41 appendError(`${String(error).toUpperCase()}<br><hr><small style='opacity:0.7'>PLEASE TRY AGAIN.</small>`)
42 loginState = 1
43 });
44 } else if (loginState == 2) {
45 if (val.trim().toLowerCase() == "y") {
46 appendNormal("Please enter your password")
47 loginState = 3
48 } else if (val.trim().toLowerCase() == "n") {
49 appendNormal("Please enter your email again")
50 loginState = 1
51 } else {
52 appendError(`UNRECOGNISED INPUT, PLEASE ENTER "Y", "N" OR "Quit"`)
53 loginState = 2
54 }
55 } else if (loginState == 3) {
56 cmdHide()
57 passLog = val
58 $d.append('<blockquote id="waitingToAdd">Authenticating user...</blockquote>')
59 addDot()
60 firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
61 .then(() => {
62 return firebase.auth().signInWithEmailAndPassword(emailLog, passLog)
63 .then((userCredential) => {
64 reloadInfo()
65 if (clearance == 5 && keyphrase != "") {
66 keyphraseLogin()
67 } else {
68 appendNormal(`Login successful - <span class="highlight">Welcome back, ${displayName}</span>`)
69 cmdShow()
70 btnShow()
71 loginState = 0
72 }
73 })

Callers 1

script.jsFile · 0.85

Calls 8

btnShowFunction · 0.90
appendNormalFunction · 0.90
cmdHideFunction · 0.90
appendErrorFunction · 0.90
cmdShowFunction · 0.90
addDotFunction · 0.90
keyphraseLoginFunction · 0.85
$Function · 0.50

Tested by

no test coverage detected