-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client login service #2678
Open
noodlemoodle
wants to merge
27
commits into
development
Choose a base branch
from
clientLoginService
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Client login service #2678
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
602055b
signin signup loginview v2 and clientloginservice initial model
noodlemoodle b7bdc6f
switch to nanos/auth/login/loginview
noodlemoodle d179865
fix action labels and actionview width
noodlemoodle 22cac93
merge dev
noodlemoodle a6ae106
adding wizard flow
noodlemoodle 40f2a69
remove loginfailed
noodlemoodle 533159c
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle 59b6589
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle 414fdf1
add wizardrunner fix
noodlemoodle 57a19ad
add showaction to resetpassword
noodlemoodle b890d6a
add fix for altflowsaver
noodlemoodle 90b8e33
fix messages
noodlemoodle ed665db
add reporting if analyticable
noodlemoodle 1933b04
fix retrievepassword for resetbycode
noodlemoodle 23f8359
add clientloginservice to services
noodlemoodle d1be896
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle ffff9a5
set trim true on identifier
noodlemoodle f3b211a
change loginview
noodlemoodle 25ffff3
fix
noodlemoodle f24fb2a
add padding
noodlemoodle 9c167d4
add property availability checks to signup
noodlemoodle 921e3a6
use validationpredicates
noodlemoodle 9f1b1ca
update validationpredicates
noodlemoodle 6b1b2d7
fix validationpredicates
noodlemoodle 1d786a1
fix validationPredicate
noodlemoodle 03df659
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle 18e5b14
use wizard emailverification
noodlemoodle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 The FOAM Authors. All Rights Reserved. | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
foam.CLASS({ | ||
package: 'foam.nanos.auth.login', | ||
name: 'ClientLoginService', | ||
|
||
imports: [ | ||
'auth', | ||
'ctrl', | ||
'defaultUserLanguage', | ||
'emailVerificationService', | ||
'loginSuccess', | ||
'notifyUser', | ||
'stack', | ||
'subject', | ||
'wizardController', | ||
'wizardletId', | ||
'wizardlets' | ||
], | ||
|
||
requires: [ | ||
'foam.log.LogLevel', | ||
'foam.nanos.auth.DuplicateEmailException', | ||
'foam.nanos.auth.login.SignIn', | ||
'foam.nanos.auth.UnverifiedEmailException', | ||
'foam.nanos.auth.User', | ||
'foam.u2.dialog.NotificationMessage', | ||
'foam.u2.stack.StackBlock' | ||
], | ||
|
||
messages: [ | ||
{ name: 'SIGNIN_ERR', message: 'There was an issue logging in' }, | ||
{ name: 'SIGNUP_ERR', message: 'There was a problem creating your account' }, | ||
{ name: 'SIGNUP_SUCCESS_MSG', message: 'Account successfully created' }, | ||
{ name: 'SIGNUP_SUCCESS_TITLE', message: 'Success' }, | ||
], | ||
|
||
methods: [ | ||
{ | ||
name: 'signin', | ||
code: async function(x, data, wizardFlow) { | ||
var analyticable = foam.nanos.analytics.Analyticable.isInstance(data); | ||
try { | ||
var loginId = data.usernameRequired_ ? data.username : data.identifier; | ||
let logedInUser = await this.auth.login(x, loginId, data.password); | ||
|
||
if ( ! logedInUser ) { | ||
if ( analyticable ) data.report('^fail-missing-subject', ['auth', 'error']); | ||
return; | ||
} | ||
|
||
data.email = logedInUser.email; | ||
data.username = logedInUser.userName; | ||
|
||
this.subject.user = logedInUser; | ||
this.subject.realUser = logedInUser; | ||
|
||
this.loginSuccess = true; | ||
await this.ctrl.reloadClient(); | ||
this.ctrl.subject = this.subject; | ||
|
||
if ( analyticable ) data.report('^success', ['auth']); | ||
|
||
if ( ! wizardFlow ) { | ||
await ctrl.checkGeneralCapability(); | ||
await ctrl.onUserAgentAndGroupLoaded(); | ||
} | ||
} catch (err) { | ||
let e = err && err.data ? err.data.exception : err; | ||
if ( this.DuplicateEmailException.isInstance(e) ) { | ||
data.email = data.identifier; | ||
if ( this.username ) { | ||
try { | ||
logedInUser = await this.auth.login(x, data.username, data.password); | ||
this.subject.user = logedInUser; | ||
this.subject.realUser = logedInUser; | ||
return; | ||
} catch ( err ) { | ||
data.username = ''; | ||
} | ||
} | ||
data.usernameRequired = true; | ||
} | ||
if ( this.UnverifiedEmailException.isInstance(e) ) { | ||
var email = this.usernameRequired ? data.email : data.identifier; | ||
if ( wizardFlow ) { | ||
this.wizardVerifyEmail(x, email, data.username, data.password); | ||
var latch = foam.core.Latch.create(); | ||
this.onDetach(this.emailVerificationService.sub('emailVerified', () => latch.resolve())); | ||
await latch; | ||
// retry signin | ||
await this.signin(x, data, true); | ||
} | ||
else await this.verifyEmail(x, email, data.username, data.password); | ||
return; | ||
} | ||
this.notifyUser(err.data, this.SIGNIN_ERR, this.LogLevel.ERROR); | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'signup', | ||
code: async function(x, data, wizardFlow) { | ||
let createdUser = this.User.create({ | ||
userName: data.username, | ||
email: data.email, | ||
desiredPassword: data.desiredPassword, | ||
language: this.defaultUserLanguage | ||
}); | ||
var user = await data.dao_.put(createdUser); | ||
if ( user ) { | ||
this.notifyUser_(this.SIGNUP_SUCCESS_TITLE, this.SIGNUP_SUCCESS_MSG, this.LogLevel.INFO); | ||
|
||
var signinModel = this.SignIn.create({ identifier: data.email, username: data.username, email: data.email, password: data.desiredPassword }); | ||
await this.signin(x, signinModel, wizardFlow) | ||
} else { | ||
this.notifyUser_(err.data, this.SIGNUP_ERR, this.LogLevel.ERROR); | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'verifyEmail', | ||
code: async function(x, email, username, password) { | ||
var signinModel = this.SignIn.create({ identifier: email, email: email, username: username, password: password }); | ||
this.onDetach(this.emailVerificationService.sub('emailVerified', async () => { | ||
await this.emailVerifiedListener(x, signinModel) | ||
})); | ||
this.stack.push(this.StackBlock.create({ | ||
view: { | ||
class: 'foam.u2.borders.StatusPageBorder', | ||
showBack: false, | ||
children: [{ | ||
class: 'foam.nanos.auth.email.VerificationCodeView', | ||
data: { | ||
class: 'foam.nanos.auth.email.EmailVerificationCode', | ||
email: email, | ||
userName: username, | ||
showAction: true | ||
} | ||
}] | ||
} | ||
}, this)); | ||
} | ||
}, | ||
{ | ||
name: 'wizardVerifyEmail', | ||
code: async function(x, email, username, password) { | ||
var ctx = this.__subContext__.createSubContext({ email: email, username: username }) | ||
const wizardRunner = foam.u2.crunch.WizardRunner.create({ | ||
wizardType: foam.u2.wizard.WizardType.UCJ, | ||
source: 'net.nanopay.auth.VerifyEmailByCode', | ||
options: { inline: false } | ||
}, ctx); | ||
|
||
await wizardRunner.launch(); | ||
} | ||
}, | ||
{ | ||
name: 'generalAdmissionsCheck', | ||
code: async function() { | ||
|
||
} | ||
}, | ||
{ | ||
name: 'resetPassword', | ||
code: async function() { | ||
this.stack.push(this.StackBlock.create({ | ||
view: { | ||
class: 'foam.nanos.auth.ChangePasswordView', | ||
modelOf: 'foam.nanos.auth.RetrievePassword' | ||
} | ||
})); | ||
} | ||
}, | ||
{ | ||
name: 'notifyUser_', | ||
code: function(err, msg, type) { | ||
this.ctrl.add(this.NotificationMessage.create({ | ||
err: err, | ||
message: msg, | ||
type: type, | ||
transient: true | ||
})); | ||
} | ||
}, | ||
{ | ||
name: 'wizardEmailVerified', | ||
code: async function(x, data) { | ||
try { | ||
await this.signin(x, data, true); | ||
this.subject = await this.auth.getCurrentSubject(null); | ||
this.loginSuccess = true; | ||
} catch (err) { | ||
this.error('^login-failed-post-verify', err); | ||
console.error(err); | ||
} | ||
} | ||
} | ||
], | ||
|
||
listeners: [ | ||
{ | ||
name: 'emailVerifiedListener', | ||
code: async function(x, data, wizardFlow) { | ||
if (wizardFlow) { | ||
await this.wizardEmailVerified(x, data); | ||
} else { | ||
await this.signin(x, data, wizardFlow); | ||
} | ||
} | ||
} | ||
] | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just use this verifyEmail flow across the board? Dont see why we need to maintain two of them