Commit 17b4fd9a by GD-A-150752

user-model-changed

parent eb83816b
...@@ -21,8 +21,8 @@ export const seedDB = async () => { ...@@ -21,8 +21,8 @@ export const seedDB = async () => {
Description: '', Description: '',
}).toPromise(), }).toPromise(),
Roles.insert({ Roles.insert({
Title: 'Blocked', Title: 'User',
Permissions: [], Permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
Description: '', Description: '',
}).toPromise(), }).toPromise(),
]); ]);
......
...@@ -15,7 +15,8 @@ Meteor.startup(() => { ...@@ -15,7 +15,8 @@ Meteor.startup(() => {
Accounts.validateLoginAttempt((data): boolean => { Accounts.validateLoginAttempt((data): boolean => {
const user: User = data.user; const user: User = data.user;
return user && user.profile.Role && UtilsService.hasPermissionOfUser(user, PERMISSIONS.CAN_LOGIN); return user && user.profile.Role
&& UtilsService.hasPermissionOfUser(user, PERMISSIONS.CAN_LOGIN);
}); });
// Changing url of reset password // Changing url of reset password
......
...@@ -15,31 +15,26 @@ Meteor.methods({ ...@@ -15,31 +15,26 @@ Meteor.methods({
}, },
registerUser(usr: any): string { registerUser(user: any): string {
const role = Roles.findOne({ Slug: usr.Role }); const myRole = Roles.findOne({ Title: user.role });
if (!Accounts.findUserByEmail(user.email)) {
if (role) { const userObj = {
if (!Accounts.findUserByEmail(usr.Email)) { email: user.email,
const user: User = { password: user.password,
email: usr.Email, username: user.username,
password: usr.Password, profile: {
username: usr.Email, Name: user.name,
profile: { Email: user.email,
FirstName: usr.FirstName, Password: user.password,
LastName: usr.LastName, Role: myRole._id,
Role: role._id, Status: user.status,
OriginalRole: role._id, RoleObj: myRole,
Status: usr.Status, },
}, };
}; return Accounts.createUser(userObj);
const createdUserId = Accounts.createUser(user);
return createdUserId;
}
throw new Meteor.Error(422, 'Email address already in use.');
} }
throw new Meteor.Error(403, 'Not Enough Permissions'); throw new Meteor.Error(422, 'Email address already in use.');
}, },
updateUser(user: User): any { updateUser(user: User): any {
...@@ -72,9 +67,9 @@ Meteor.methods({ ...@@ -72,9 +67,9 @@ Meteor.methods({
async enableUser(user: User): Promise<any> { async enableUser(user: User): Promise<any> {
if (UtilsService.hasPermission(PERMISSIONS.CAN_UPDATE_USER)) { if (UtilsService.hasPermission(PERMISSIONS.CAN_UPDATE_USER)) {
const role = Roles.findOne({ Slug: user.profile.OriginalRole }); // const role = Roles.findOne({ Slug: user.profile.OriginalRole });
const usr = Meteor.users.findOne(user._id); const usr = Meteor.users.findOne(user._id);
usr.profile.Role = role._id; // usr.profile.Role = role._id;
return Meteor.users.update(user._id, usr); return Meteor.users.update(user._id, usr);
} }
......
...@@ -7,23 +7,16 @@ export interface User { ...@@ -7,23 +7,16 @@ export interface User {
password?: string; password?: string;
username?: string; username?: string;
profile?: UserProfile; profile?: UserProfile;
Role?: any;
OldPassword?: string; OldPassword?: string;
NewPassword?: string; NewPassword?: string;
ConfirmNewPassword?: string; ConfirmNewPassword?: string;
} }
export interface UserProfile { export interface UserProfile {
FirstName?: string; Name?: string;
LastName?: string; Email: string;
Role?: string; Password: string;
OriginalRole?: string; Role: string;
RoleTitle?: string;
RoleObj?: Role; RoleObj?: Role;
AccountActiveUntil?: Date;
Phone?: string;
Address?: string;
Email?: string;
Password?: string;
Status?: 'ACTIVE' | 'DISABLED'; Status?: 'ACTIVE' | 'DISABLED';
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment