Skip to content
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
wants to merge 27 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Apr 4, 2023
b7bdc6f
switch to nanos/auth/login/loginview
noodlemoodle Apr 4, 2023
d179865
fix action labels and actionview width
noodlemoodle Apr 4, 2023
22cac93
merge dev
noodlemoodle Apr 11, 2023
a6ae106
adding wizard flow
noodlemoodle Apr 12, 2023
40f2a69
remove loginfailed
noodlemoodle Apr 12, 2023
533159c
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle Apr 12, 2023
59b6589
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle Apr 14, 2023
414fdf1
add wizardrunner fix
noodlemoodle Apr 14, 2023
57a19ad
add showaction to resetpassword
noodlemoodle Apr 14, 2023
b890d6a
add fix for altflowsaver
noodlemoodle Apr 16, 2023
90b8e33
fix messages
noodlemoodle Apr 17, 2023
ed665db
add reporting if analyticable
noodlemoodle Apr 17, 2023
1933b04
fix retrievepassword for resetbycode
noodlemoodle Apr 17, 2023
23f8359
add clientloginservice to services
noodlemoodle Apr 17, 2023
d1be896
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle Apr 26, 2023
ffff9a5
set trim true on identifier
noodlemoodle Apr 26, 2023
f3b211a
change loginview
noodlemoodle Apr 26, 2023
25ffff3
fix
noodlemoodle Apr 26, 2023
f24fb2a
add padding
noodlemoodle Apr 26, 2023
9c167d4
add property availability checks to signup
noodlemoodle Apr 27, 2023
921e3a6
use validationpredicates
noodlemoodle Apr 27, 2023
9f1b1ca
update validationpredicates
noodlemoodle May 1, 2023
6b1b2d7
fix validationpredicates
noodlemoodle May 1, 2023
1d786a1
fix validationPredicate
noodlemoodle May 1, 2023
03df659
Merge branch 'development' of https://github.com/kgrgreer/foam3 into …
noodlemoodle May 1, 2023
18e5b14
use wizard emailverification
noodlemoodle May 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/foam/nanos/auth/RetrievePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ foam.CLASS({
type: this.LogLevel.INFO,
transient: true
}));
this.stack.push({ ...(this.loginView ?? { class: 'foam.u2.view.LoginView' }), mode_: 'SignIn' }, this);
if ( ! this.resetByCode ) this.stack.push({ ...(this.loginView ?? { class: 'foam.nanos.auth.login.LoginView' }), mode_: 0 }, this);
} catch(err) {
var msg = this.ERROR_MSG;
if ( this.UserNotFoundException.isInstance(err.data.exception) ) {
Expand Down
3 changes: 2 additions & 1 deletion src/foam/nanos/auth/email/EmailVerificationCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ foam.CLASS({
if ( success ) {
this.ctrl.add(this.NotificationMessage.create({
message: this.SUCCESS_MSG,
type: this.LogLevel.INFO
type: this.LogLevel.INFO,
transient: true
}));
this.emailVerificationService.pub('emailVerified');
} else {
Expand Down
217 changes: 217 additions & 0 deletions src/foam/nanos/auth/login/ClientLoginService.js
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) {
Copy link
Collaborator

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

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);
}
}
}
]
});
Loading