public static async Task<bool> ChangePasswordAsync(AppUser current, ChangePassword model, RemoteUser user) { int userId = current.UserId; if (userId <= 0) { await Task.Delay(5000).ConfigureAwait(false); return false; } if (model.Password != model.ConfirmPassword) { return false; } string email = current.Email; var frapidUser = await Users.GetAsync(current.Tenant, email).ConfigureAwait(false); bool oldPasswordIsValid = PasswordManager.ValidateBcrypt(model.OldPassword, frapidUser.Password); if (!oldPasswordIsValid) { await Task.Delay(2000).ConfigureAwait(false); return false; } string newPassword = PasswordManager.GetHashedPassword(model.Password); await Users.ChangePasswordAsync(current.Tenant, userId, newPassword, user).ConfigureAwait(false); return true; }
internal static async Task<IEnumerable<MenuAccessPolicy>> GetAsync(AppUser appUser, int officeId, int userId) { if (!appUser.IsAdministrator) { return new List<MenuAccessPolicy>(); } return await Menus.GetPolicyAsync(appUser.Tenant, officeId, userId).ConfigureAwait(false); }
public static async Task SaveAsync(AppUser appUser, int officeId, int roleId, List<AccessPolicyInfo> model) { if (!appUser.IsAdministrator) { return; } await AccessPolicy.SaveGroupPolicyAsync(appUser.Tenant, officeId, roleId, model).ConfigureAwait(false); }
internal static async Task<List<AccessPolicyInfo>> GetAsync(AppUser appUser, int officeId, int roleId) { if (!appUser.IsAdministrator) { return new List<AccessPolicyInfo>(); } var data = await AccessPolicy.GetGroupPolicyAsync(appUser.Tenant, officeId, roleId).ConfigureAwait(false); return data.Adapt<List<AccessPolicyInfo>>(); }
public static async Task SaveAsync(AppUser appUser, GroupMenuPolicyInfo model) { if (!appUser.IsAdministrator) { return; } await Menus.SaveGroupPolicyAsync(appUser.Tenant, model.OfficeId, model.RoleId, model.MenuIds) .ConfigureAwait(false); }
protected override void Initialize(HttpControllerContext context) { this.Tenant = TenantConvention.GetTenant(); string clientToken = context.Request.GetBearerToken(); var provider = new Provider(); var token = provider.GetToken(clientToken); if(token != null) { AppUsers.SetCurrentLoginAsync(this.Tenant, token.LoginId).Wait(); var loginView = AppUsers.GetCurrentAsync(this.Tenant, token.LoginId).Result; this.AppUser = new AppUser { Tenant = this.Tenant, ClientToken = token.ClientToken, LoginId = token.LoginId, UserId = loginView.UserId, Name = loginView.Name, OfficeId = loginView.OfficeId, OfficeName = loginView.OfficeName, Email = loginView.Email, RoleId = loginView.RoleId, RoleName = loginView.RoleName, IsAdministrator = loginView.IsAdministrator }; var identity = new ClaimsIdentity(token.GetClaims()); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, token.LoginId.ToString(CultureInfo.InvariantCulture))); if(this.AppUser.RoleName != null) { identity.AddClaim(new Claim(ClaimTypes.Role, this.AppUser.RoleName)); } if(this.AppUser.Email != null) { identity.AddClaim(new Claim(ClaimTypes.Email, this.AppUser.Email)); } context.RequestContext.Principal = new ClaimsPrincipal(identity); } base.Initialize(context); }
internal static async Task<GroupMenuPolicyInfo> GetAsync(AppUser appUser, int officeId, int roleId) { if (!appUser.IsAdministrator) { return new GroupMenuPolicyInfo(); } var menuIds = await Menus.GetGroupPolicyAsync(appUser.Tenant, officeId, roleId).ConfigureAwait(false); return new GroupMenuPolicyInfo { RoleId = roleId, OfficeId = officeId, MenuIds = menuIds }; }
public static async Task<UserMenuPolicy> GetAsync(AppUser appUser) { if (!appUser.IsAdministrator) { return new UserMenuPolicy(); } var offices = await Offices.GetOfficesAsync(appUser.Tenant).ConfigureAwait(false); var users = await Users.GetUsersAsync(appUser.Tenant).ConfigureAwait(false); var menus = await Menus.GetMenusAsync(appUser.Tenant).ConfigureAwait(false); return new UserMenuPolicy { Menus = menus, Offices = offices, Users = users }; }
public static async Task<GroupEntityAccessPolicy> GetAsync(AppUser appUser) { if (!appUser.IsAdministrator) { return new GroupEntityAccessPolicy(); } var offices = await Offices.GetOfficesAsync(appUser.Tenant).ConfigureAwait(false); var roles = await Roles.GetRolesAsync(appUser.Tenant).ConfigureAwait(false); return new GroupEntityAccessPolicy { Offices = offices, Roles = roles, AccessTypes = AccessType.GetAccessTypes(), Entities = await Entity.GetEntitiesAsync(appUser.Tenant).ConfigureAwait(false) }; }
public static async Task<GroupMenuPolicy> GetAsync(AppUser appUser) { if (!appUser.IsAdministrator) { return new GroupMenuPolicy(); } var offices = await Offices.GetOfficesAsync(appUser.Tenant).ConfigureAwait(false); var roles = await Roles.GetRolesAsync(appUser.Tenant).ConfigureAwait(false); var menus = await Menus.GetMenusAsync(appUser.Tenant).ConfigureAwait(false); return new GroupMenuPolicy { Menus = menus, Offices = offices, Roles = roles }; }