本文整理汇总了C#中IMembershipService.ChangeUserName方法的典型用法代码示例。如果您正苦于以下问题:C# IMembershipService.ChangeUserName方法的具体用法?C# IMembershipService.ChangeUserName怎么用?C# IMembershipService.ChangeUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMembershipService
的用法示例。
在下文中一共展示了IMembershipService.ChangeUserName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AccountModule
//.........这里部分代码省略.........
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
Request.AddAlertMessage("success", "Successfully added a password.");
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changepassword"] = _ =>
{
if (!applicationSettings.AllowUserRegistration)
{
return HttpStatusCode.NotFound;
}
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string oldPassword = Request.Form.oldPassword;
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
if (String.IsNullOrEmpty(oldPassword))
{
this.AddValidationError("oldPassword", "Old password is required");
}
ValidatePassword(password, confirmPassword);
ChatUser user = repository.GetUserById(Principal.GetUserId());
try
{
if (ModelValidationResult.IsValid)
{
membershipService.ChangeUserPassword(user, oldPassword, password);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
Request.AddAlertMessage("success", "Successfully changed your password.");
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changeusername"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string username = Request.Form.username;
string confirmUsername = Request.Form.confirmUsername;
ValidateUsername(username, confirmUsername);
ChatUser user = repository.GetUserById(Principal.GetUserId());
string oldUsername = user.Name;
try
{
if (ModelValidationResult.IsValid)
{
membershipService.ChangeUserName(user, username);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
notificationService.OnUserNameChanged(user, oldUsername, username);
Request.AddAlertMessage("success", "Successfully changed your username.");
return Response.AsRedirect("~/account/#changeUsername");
}
return GetProfileView(authService, user);
};
}
示例2: AccountModule
//.........这里部分代码省略.........
{
membershipService.SetUserPassword(user, password);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
this.AddAlertMessage("success", "Successfully added a password.");
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changepassword"] = _ =>
{
if (Context.CurrentUser == null)
{
return HttpStatusCode.Forbidden;
}
string oldPassword = Request.Form.oldPassword;
string password = Request.Form.password;
string confirmPassword = Request.Form.confirmPassword;
if (String.IsNullOrEmpty(oldPassword))
{
this.AddValidationError("oldPassword", "Old password is required");
}
ValidatePassword(password, confirmPassword);
ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);
try
{
if (ModelValidationResult.IsValid)
{
membershipService.ChangeUserPassword(user, oldPassword, password);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
this.AddAlertMessage("success", "Successfully changed your password.");
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changeusername"] = _ =>
{
if (Context.CurrentUser == null)
{
return HttpStatusCode.Forbidden;
}
string username = Request.Form.username;
string confirmUsername = Request.Form.confirmUsername;
ValidateUsername(username, confirmUsername);
ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);
string oldUsername = user.Name;
try
{
if (ModelValidationResult.IsValid)
{
membershipService.ChangeUserName(user, username);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
notificationService.OnUserNameChanged(user, oldUsername, username);
this.AddAlertMessage("success", "Successfully changed your username.");
return Response.AsRedirect("~/account/#changeUsername");
}
return GetProfileView(authService, user);
};
}
示例3: AccountModule
//.........这里部分代码省略.........
if (ModelValidationResult.IsValid)
{
Request.AddAlertMessage("success", LanguageResources.Authentication_PassChangeSuccess);
return Response.AsRedirect("~/account/#changePassword");
}
return GetProfileView(authService, user);
};
Post["/changeusername"] = _ =>
{
if (!HasValidCsrfTokenOrSecHeader)
{
return HttpStatusCode.Forbidden;
}
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
string username = Request.Form.username;
string confirmUsername = Request.Form.confirmUsername;
ValidateUsername(username, confirmUsername);
ChatUser user = repository.GetUserById(Principal.GetUserId());
string oldUsername = user.Name;
try
{
if (ModelValidationResult.IsValid)
{
membershipService.ChangeUserName(user, username);
repository.CommitChanges();
}
}
catch (Exception ex)
{
this.AddValidationError("_FORM", ex.Message);
}
if (ModelValidationResult.IsValid)
{
notificationService.OnUserNameChanged(user, oldUsername, username);
Request.AddAlertMessage("success", LanguageResources.Authentication_NameChangeCompleted);
return Response.AsRedirect("~/account/#changeUsername");
}
return GetProfileView(authService, user);
};
Get["/requestresetpassword"] = _ =>
{
if (IsAuthenticated)
{
return Response.AsRedirect("~/account/#changePassword");
}
if (!Principal.Identity.IsAuthenticated &&
!applicationSettings.AllowUserResetPassword ||
string.IsNullOrWhiteSpace(applicationSettings.EmailSender))
{
return HttpStatusCode.NotFound;
}