2012-01-18 104 views
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); 
} 

回答

2

你想看看configuring an Area为您的网站。

从链接:

为了适应大项目,ASP.NET MVC,您可以分区Web应用程序 成被称为区域较小的单位。区域 提供了一种将大型MVC Web应用程序分成更小的功能分组的方法。一个区域实际上是一个应用程序中的 内的MVC结构。一个应用程序可能包含几个MVC结构 (区域)。

例如,一个大的电子商务应用程序可以被划分成 代表的店面面积,产品评测,用户 帐户管理和采购系统。每个区域 代表整个应用程序的单独功能。

+1

要添加到Jasons评论,我也鼓励这个任务的领域。您需要构建一组控制器,视图以及可能的模型来支持您的管理员区域。由于您使用的是成员资格提供商,您应该使用授权过滤器修饰您的控制器或控制器操作,以便只允许管理员访问该区域。 – 2012-01-18 14:57:53

相关问题