MongoDb Schema for Account creation with subscription plan - javascript

I have to create an Account creation schema which is basically a three-step process.
In step 1, we have Email-id with a password and confirm the password.
step 2: User can select the subscription plan which is basic, standard and premium .then after
step3: Payment module where we ask for card details and payment for the selected plan.
after the successful subscription user redirected into the dashboard. I have to design the schema.

Step 1 - there is no reason to keep confirmation password. this should be checked in client side only.
So we need only the email and password (hashed: password + salt[email/userid])
Make sure when user register you check the email
Step 2 - should be index let's say 0-not subscribed, 1-basic, 2-standard, 3-premium
Step 3 - This better for you not to keep. just use the API of online clearing to get the payment and confirmation of the payment.
I would have added the fields of subscribe date. and the date the subscription will expired.
good luck.
EDITED
let schema = new Schema({
email: { type: String, validate: validateEmail }, //The validate Email should be a function that get as value the email and return true or false if it is valid! (email format/not duplicated)
subscription: { type: Number },// 0-non. 1-basic, 2-standard, 3-premium (this will be set by the payment)
subscriptionDate: { type: Date },
subscriptionExpr: { type: Date }//This also will be set by the payment, and will be checked before any service giving. making sure the subscription is still valid.
});
This is the most basic form of scheme you need. you could make it more complex by making the last three fields in array for tracking past subscription plans the user had or so.

Related

Cognito user pool "username" appears as id not email, how to fix it?

I'm using Amazon Cognito user pools, and i choose to have users signup/In with their emails. According to online guides, when choosing so, the user pool should list users with "username" value as their email, but this is not the case, i'm seeing the "id" which is also referred to as "sub" as the "username" field!
it has the UUID format.
Any ideas how to get username shows the email?
** Note: I'm talking about showing users from AWS cognito console.
Attached is a screenshot
That seems to happen when you chose to signup with either email or phone.
Apparently in that configuration Cognito generates 'username' using the sub...
I would suggest configuring Congito to use 'username' and then on signup set up the 'username' to email, you can also pass email (and phone) as additional attributes.
I hope that helps
#Luke is correct, this only happens when you select the "Email address or phone number" option in the "How do you want your end users to sign in" section of the wizard.
It's a bit confusing because the SignUp API expects an email-formatted username during signup, but then ends up creating a user with a GUID as a username, and assigns the submitted username to the email attribute. This is described in the docs:
Call the SignUp API and pass an email address or phone number in the username parameter of the API. This API does the following:
If the username string is in valid email format, the user pool automatically populates the email attribute of the user with the username value.
If the username string format is not in email or phone number format, the SignUp API throws an exception.
The SignUp API generates a persistent UUID for your user, and uses it as the immutable username attribute internally. This UUID has the same value as the sub claim in the user identity token.
If the username string contains an email address or phone number that is already in use, the SignUp API throws an exception.
This is in fact probably what you want though, as it allows users to change their emails down the line (as actual usernames cannot be changed). And furthermore, the docs state that "You can use an email address or phone number as an alias in place of the username in all APIs except the ListUsers API", so the fact that the username is a GUID in the backend doesn't have much effect on how you interact with the API.
As for listing the email in the console, it looks like they've added an email column in the user list, so that shouldn't be a problem anymore.
Here you have an example.
auth.service.ts
you have to do the login method for Cognito in your authentication service. Something like this:
login(username: string, password: string): Promise<CognitoUser|any> {
return new Promise((resolve,reject) => {
Auth.signIn(username,password)
.then((user: CognitoUser|any) => {
this.currentUserSubject.next(user);
localStorage.setItem("currentUser", JSON.stringify(user));
localStorage.setItem("token", user.signInUserSession.idToken.jwtToken);
localStorage.setItem("userGroup", user.signInUserSession.idToken.payload['cognito:groups']);
localStorage.setItem("userEmail", user.attributes.email);
this.loggedIn = true;
resolve(user);
}).catch((error: any) => reject(error));
});
}
and then in the .ts of your component you have to do the call of that method in the constructor and store in a variable the userEmail argument that you get in the localStorage from Cognito:
constructor(
private authService: AuthService,
) {
this.authService.currentUser.subscribe(response => {
this.currentUser = response;
});
this.userSessionName = localStorage.getItem('userEmail');
}
Finally, you have to display the userSessionName variable in you .html component:
<p>{{ userSessionName }}</p>

Meteor: Two types of user, the way to go with complexe UserAccounts?

I'm using Meteor/react and flowRouter and I would like to create an app with two kinds of users; let's say the stay simple:
Client
Provider
In fact Client has some "UserAccounts" fields (name, password, email ...) but I would like to add many of others: Idk like Passport Number, Social Security Number, Bank Account etc ...
The Provider could fill this fields if he wants too (so could have the same "role") but its main goal is to have other fields like idk: Job title, Category Job, Other Password etc ..
So Is some of you used the package UserAccounts to do this or you created a system by yourself ?
Of course I wish using email validation etc ... The application Ui would like to have a search component searching for Providers and only in Providers.
Also, I will use two Registration form (same page but two forms) but one Login modal for both types.
My question is, is it a good thing to use userAccount, and probably I will need roles for the two roles, but do UserAccount accept many others custom fields, do I have to set in in 'Profile' and won't it slow too much the application with only one user collection ?
Thanks guys for the mind blowing help :)
Yes, you can use userAccount for your case & No, it won't slow down to any noticeable amount.
To manage different roles you can use alaning:roles package. It helps you limit access to certain parts of code to roles and groups.
UPDATE: (Edit)
As Pointed out in comments, it is not advisable to use profile as it is automatically publishes. Instead try this:
Regarding, second part of adding more fields in user account, you can add any number of fields in the profile section. The document will look something like this:
{
_id: "bbca5d6a-2156-41c4-89da-0329e8c99a4f", // Meteor.userId()
username: "cool_kid_13", // unique name
emails: [
// each email address can only belong to one user.
{ address: "cool#example.com", verified: true },
{ address: "another#different.com", verified: false }
],
createdAt: Wed Aug 21 2013 15:16:52 GMT-0700 (PDT),
profile: {
//profile data
},
passportNo:'PASSPORT',
ssn:'SSSN',
oneMoreField: 'OneMoreField',
}
By default, here only email, username and profile will be published and your other data will not be visible to client unless published and subscribed.
You can read more about accounts here

Check for new user

I want to know when a user logs in via a provider(twitter,facebook,etc...) If he is a new user. If so then add his data to my firebase.. Currently i have read this:
https://www.firebase.com/docs/web/guide/user-auth.html
And it tells me to do:
var isNewUser = true;
Then check by saying
if(authData && isNewUser){
//This is a new user
}
But it dosent work... I logged in with the same account but it tells me its a new user...
Generally with Firebase, you would have a /users node where you would store other data about your users
users
user_id_0
name: "Buck Murdock"
email: "buck#moonbasealphabeta"
user_id_1
name: "Ted Striker"
email: "ted#airplane.com"
The user_id is the Firebase assigned user id.
When a user starts to access your App, you would query your /users node to see if, for example, their email already exists. If not, then you create the user and add them to the /users node.
Oh - and refer to the section Storing User Data in the Firebase guide as you may have overlooked the comment
// here we will just simulate this with an isNewUser boolean

Meteor login email domain predefined

I want to make a Meteor app where users can only create an account if their email ends with #mydomain.com.
In the end, they would actually only need to enter their username and not the #mydomain.com part.
So, the create user field would look like:
Name: __________
eMail: __________#mydomain.com
Password: __________
Renter: __________
How would I go about doing this?
You use accounts package: meteor add accounts-password.
Then you would configure it in server-side code (http://docs.meteor.com/#accounts_config): Accounts.config({restrictCreationByEmailDomain:'mydomain.com'});
And then use Accounts.createUser in combination with custom UI that autofills the email domain part.
I'm assuming you're using Meteor's built-in accounts management packages. To limit signups to mydomain.com email addresses, put the following in server-side code:
Accounts.validateNewUser(function(user) {
if (/#mydomain\.com$/.test(user.emails[0].address.toLowerCase())) {
return true;
} else {
throw new Meteor.Error(403, "Email domain not allowed.");
}
});
As for helping them with adding the #mydomain.com, write some client-side code that validates the field in the login form where they enter their username. If it lacks an #, tack #mydomain.com onto the end of it before the form gets submitted.

Meteor js - "please re-enter your password to do that" - how to reauth while already logged in?

In Meteor, how do i check if some input password string matches the currently logged-in user's actual password? I'm looking to have certain more sensitive settings only be able to be changed if you re-enter your password, similar to how github does sensitive stuff.
In the application I'm working on, a shift manager will sign into the meteor app at the beginning of the day, and this unlocks the UI for employees / cashiers to use until the manager signs out. However, while the manager is doing something else, if an employee tries to, say, edit the cash drawer totals, they'll be prompted for the manager's password. If they enter an incorrect password, it just shouldn't let them do that operation, but it shouldn't log them out.
Where userPassword is the user submitted password. Note there is no underscore before id.
Meteor.loginWithPassword({id: localStorage['Meteor.userId'] }, userPassword, function (error) {
if(!error) {
// good to go.
} else {
// not this time, pal.
}
});

Categories