Commit 17b4fd9a by GD-A-150752

user-model-changed

parent eb83816b
......@@ -21,8 +21,8 @@ export const seedDB = async () => {
Description: '',
}).toPromise(),
Roles.insert({
Title: 'Blocked',
Permissions: [],
Title: 'User',
Permissions: [PERMISSIONS.CAN_LOGIN, PERMISSIONS.CAN_UPDATE_OWN_USER],
Description: '',
}).toPromise(),
]);
......
......@@ -15,7 +15,8 @@ Meteor.startup(() => {
Accounts.validateLoginAttempt((data): boolean => {
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
......
......@@ -15,31 +15,26 @@ Meteor.methods({
},
registerUser(usr: any): string {
const role = Roles.findOne({ Slug: usr.Role });
registerUser(user: any): string {
const myRole = Roles.findOne({ Title: user.role });
if (!Accounts.findUserByEmail(user.email)) {
if (role) {
if (!Accounts.findUserByEmail(usr.Email)) {
const user: User = {
email: usr.Email,
password: usr.Password,
username: usr.Email,
profile: {
FirstName: usr.FirstName,
LastName: usr.LastName,
Role: role._id,
OriginalRole: role._id,
Status: usr.Status,
},
};
const createdUserId = Accounts.createUser(user);
return createdUserId;
}
throw new Meteor.Error(422, 'Email address already in use.');
const userObj = {
email: user.email,
password: user.password,
username: user.username,
profile: {
Name: user.name,
Email: user.email,
Password: user.password,
Role: myRole._id,
Status: user.status,
RoleObj: myRole,
},
};
return Accounts.createUser(userObj);
}
throw new Meteor.Error(403, 'Not Enough Permissions');
throw new Meteor.Error(422, 'Email address already in use.');
},
updateUser(user: User): any {
......@@ -72,9 +67,9 @@ Meteor.methods({
async enableUser(user: User): Promise<any> {
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);
usr.profile.Role = role._id;
// usr.profile.Role = role._id;
return Meteor.users.update(user._id, usr);
}
......
......@@ -7,23 +7,16 @@ export interface User {
password?: string;
username?: string;
profile?: UserProfile;
Role?: any;
OldPassword?: string;
NewPassword?: string;
ConfirmNewPassword?: string;
}
export interface UserProfile {
FirstName?: string;
LastName?: string;
Role?: string;
OriginalRole?: string;
RoleTitle?: string;
Name?: string;
Email: string;
Password: string;
Role: string;
RoleObj?: Role;
AccountActiveUntil?: Date;
Phone?: string;
Address?: string;
Email?: string;
Password?: string;
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