I’m working on an MVC webapp and am done with the registration module that uses the SQL Membership tables.
Now, I have written code that, when a user gets created and is approved, the application sends an email to the user with an activation link in email.
Now I want to create an admin page where admin can approve those registered users
How can I do this?
code:
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("contacts@abc.com", user.Email)
{
Subject = "Please confirm your email",
Body = verifyUrl
};
var client = new SmtpClient();
client.Send(message);
}
You want to look into configuring an Area for your site.
From the link: