public object SignIn(Membership membership) { IRepository repo = new Repository(); membership.LastLoginDate = DateTime.Now; repo.Update(membership); UserDto.SetSession(membership.ID); return(membership.ID); }
public static bool ValidateUser(string username, out Membership membership) { Contract.Requires(!string.IsNullOrEmpty(username)); IRepository repo = new Repository(); var query = repo.Query <Membership>(x => x.UserName == username); if (query.Any()) { membership = query[0]; } else { membership = null; } return(query.Any()); }
public object SignIn(Membership membership) { IRepository repo = new Repository(); membership.LastLoginDate = DateTime.Now; repo.Update(membership); UserDto.SetSession(membership.ID); return membership.ID; }
public static bool ValidateUser(string username, out Membership membership) { Contract.Requires(!string.IsNullOrEmpty(username)); IRepository repo = new Repository(); var query = repo.Query<Membership>(x => x.UserName == username); if (query.Any()) { membership = query[0]; } else { membership = null; } return query.Any(); }
// Summary: // Updates the password for the membership user in the membership data store. // // Parameters: // oldPassword: // The current password for the membership user. // // newPassword: // The new password for the membership user. // // Returns: // true if the update was successful; otherwise, false. // // Exceptions: // System.ArgumentException: // oldPassword is an empty string.-or-newPassword is an empty string. // // System.ArgumentNullException: // oldPassword is null.-or-newPassword is null. // // System.PlatformNotSupportedException: // This method is not available. This can occur if the application targets the // .NET Framework 4 Client Profile. To prevent this exception, override the // method, or change the application to target the full version of the .NET // Framework. public static bool ChangePassword(Membership instance, string oldPassword, string newPassword) { Contract.Requires(!string.IsNullOrEmpty(oldPassword)); Contract.Requires(!string.IsNullOrEmpty(newPassword)); if (oldPassword.Equals(newPassword, StringComparison.OrdinalIgnoreCase)) { throw new Exception("新密码应与旧密码不同"); } if (!instance.Password.Equals(Encrypt.GetMd5Hash(oldPassword))) { throw new Exception("用户旧密码验证不正确"); } using (var conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); var trans = conn.BeginTransaction(); try { IRepository repo = new Repository(); instance.Password = Encrypt.GetMd5Hash(newPassword); instance.LastPasswordChangedDate = DateTime.Now; repo.Update(instance, trans); #region Sync Acn User Password if (ConfigGlobal_Arsenal.AcnSync) { var user = repo.Single<User>(instance.ID); if (user?.AcnID != null) { var client = new DiscuzApiClient(); var result = client.UsersChangePassword(user.AcnID.Value, Encrypt.GetMd5Hash(oldPassword), Encrypt.GetMd5Hash(newPassword)); if (!Convert.ToBoolean(result.Replace("\"", ""))) { throw new Exception("ACN同步失败"); } } } #endregion trans.Commit(); return true; } catch { trans.Rollback(); throw; } } }
// Summary: // Updates the password for the membership user in the membership data store. // // Parameters: // oldPassword: // The current password for the membership user. // // newPassword: // The new password for the membership user. // // Returns: // true if the update was successful; otherwise, false. // // Exceptions: // System.ArgumentException: // oldPassword is an empty string.-or-newPassword is an empty string. // // System.ArgumentNullException: // oldPassword is null.-or-newPassword is null. // // System.PlatformNotSupportedException: // This method is not available. This can occur if the application targets the // .NET Framework 4 Client Profile. To prevent this exception, override the // method, or change the application to target the full version of the .NET // Framework. public static bool ChangePassword(Membership instance, string oldPassword, string newPassword) { Contract.Requires(!string.IsNullOrEmpty(oldPassword)); Contract.Requires(!string.IsNullOrEmpty(newPassword)); if (oldPassword.Equals(newPassword, StringComparison.OrdinalIgnoreCase)) { throw new Exception("新密码应与旧密码不同"); } if (!instance.Password.Equals(Encrypt.GetMd5Hash(oldPassword))) { throw new Exception("用户旧密码验证不正确"); } using (var conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); var trans = conn.BeginTransaction(); try { IRepository repo = new Repository(); instance.Password = Encrypt.GetMd5Hash(newPassword); instance.LastPasswordChangedDate = DateTime.Now; repo.Update(instance, trans); #region Sync Acn User Password if (ConfigGlobal_Arsenal.AcnSync) { var user = repo.Single <User>(instance.ID); if (user?.AcnID != null) { var client = new DiscuzApiClient(); var result = client.UsersChangePassword(user.AcnID.Value, Encrypt.GetMd5Hash(oldPassword), Encrypt.GetMd5Hash(newPassword)); if (!Convert.ToBoolean(result.Replace("\"", ""))) { throw new Exception("ACN同步失败"); } } } #endregion trans.Commit(); return(true); } catch { trans.Rollback(); throw; } } }