0
我正在处理MVC web应用程序,并使用SQL成员表的注册模块完成。如何在MVC中为注册用户创建管理模块?
现在,我已经编写了代码,当用户创建并获得批准后,应用程序会通过电子邮件中的激活链接向用户发送电子邮件。
现在我想创建一个管理员页面,管理员可以审批这些注册用户
我怎样才能做到这一点?
代码:
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
if (createStatus == MembershipCreateStatus.Success)
{
// FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
//used profiler -- add profile information
var profile = Profile.GetProfile(model.UserName);
profile.FirstName = model.FirstName;
profile.LastName = model.LastName;
profile.Save();
//email confirmation code
MembershipService.SendConfirmationEmail(model.UserName);
return RedirectToAction("Confirmation");
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View(model);
}
//send confirmation code
public void SendConfirmationEmail(string userName)
{
MembershipUser user = Membership.GetUser(userName);
string confirmationGuid = user.ProviderUserKey.ToString();
string verifyUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
"/account/verify?ID=" + confirmationGuid;
var message = new MailMessage("[email protected]", user.Email)
{
Subject = "Please confirm your email",
Body = verifyUrl
};
var client = new SmtpClient();
client.Send(message);
}
要添加到Jasons评论,我也鼓励这个任务的领域。您需要构建一组控制器,视图以及可能的模型来支持您的管理员区域。由于您使用的是成员资格提供商,您应该使用授权过滤器修饰您的控制器或控制器操作,以便只允许管理员访问该区域。 – 2012-01-18 14:57:53