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