public async Task<LoginResult> AuthenticateAsync(FacebookAccount account, RemoteUser user) { var facebookUser = GetFacebookUserInfo(account.Token); if (!Validate(facebookUser, account.FacebookUserId, account.Email)) { return new LoginResult { Status = false, Message = "Access is denied" }; } var result = await FacebookSignIn.SignInAsync(this.Tenant, account.FacebookUserId, account.Email, account.OfficeId, facebookUser.Name, account.Token, user.Browser, user.IpAddress, account.Culture).ConfigureAwait(false); if (result.Status) { if (!await Registrations.HasAccountAsync(this.Tenant, account.Email).ConfigureAwait(false)) { string template = "~/Tenants/{tenant}/Areas/Frapid.Account/EmailTemplates/welcome-email-other.html"; var welcomeEmail = new WelcomeEmail(facebookUser, template, ProviderName); await welcomeEmail.SendAsync(this.Tenant).ConfigureAwait(false); } } return result; }
public async Task<LoginResult> AuthenticateAsync(GoogleAccount account, RemoteUser user) { bool validationResult = Task.Run(() => ValidateAsync(account.Token)).Result; if (!validationResult) { return new LoginResult { Status = false, Message = "Access is denied" }; } var gUser = new GoogleUserInfo { Email = account.Email, Name = account.Name }; var result = GoogleSignIn.SignIn(account.Email, account.OfficeId, account.Name, account.Token, user.Browser, user.IpAddress, account.Culture); if (result.Status) { if (!Registrations.HasAccount(account.Email)) { string template = "~/Catalogs/{catalog}/Areas/Frapid.Account/EmailTemplates/welcome-email-other.html"; var welcomeEmail = new WelcomeEmail(gUser, template, ProviderName); await welcomeEmail.SendAsync(); } } return result; }
public static async Task<bool> SignUpAsync(HttpContextBase context, string tenant, Registration model, RemoteUser user) { if (model.Password != model.ConfirmPassword) { throw new PasswordConfirmException("Passwords do not match."); } if (model.Email != model.ConfirmEmail) { throw new PasswordConfirmException("Emails do not match."); } model.Browser = user.Browser; model.IpAddress = user.IpAddress; var registration = model.Adapt<DTO.Registration>(); registration.Password = PasswordManager.GetHashedPassword(model.Password); string registrationId = (await Registrations.RegisterAsync(tenant, registration).ConfigureAwait(false)).ToString(); if (string.IsNullOrWhiteSpace(registrationId)) { return false; } var email = new SignUpEmail(context, registration, registrationId); await email.SendAsync(tenant).ConfigureAwait(false); return true; }
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; }
protected FrapidController() { this.RemoteUser = new RemoteUser { Browser = this.Request?.Browser.Browser, IpAddress = this.Request?.UserHostAddress, Culture = CultureManager.GetCurrent().Name }; }
protected override void OnActionExecuting(ActionExecutingContext context) { if (this.Request?.Url != null) { this.CurrentDomain = this.Request.Url.DnsSafeHost; this.CurrentPageUrl = this.Request.Url.AbsoluteUri; this.Tenant = TenantConvention.GetTenant(this.CurrentDomain); } this.RemoteUser = RemoteUser.Get(this.HttpContext); this.Initialize(context.RequestContext); }
public static async Task ChangePasswordAsync(string tenant, int userId, string newPassword, RemoteUser remoteUser) { using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase()) { var sql = new Sql("UPDATE account.users SET"); sql.Append("password=@0,", newPassword); sql.Append("audit_user_id=@0,", userId); sql.Append("audit_ts=@0,", DateTimeOffset.UtcNow); sql.Append("last_ip=@0,", remoteUser.IpAddress); sql.Append("last_seen_on=@0", DateTimeOffset.UtcNow); sql.Where("user_id=@0", userId); await db.NonQueryAsync(sql).ConfigureAwait(false); } }
protected override void OnActionExecuting(ActionExecutingContext context) { this.RemoteUser = new RemoteUser { Browser = this.Request?.Browser.Browser, IpAddress = this.Request?.UserHostAddress, Culture = CultureManager.GetCurrent().Name, UserAgent = this.Request?.UserAgent }; }