本文整理汇总了C#中UserManager.GenerateEmailConfirmationToken方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.GenerateEmailConfirmationToken方法的具体用法?C# UserManager.GenerateEmailConfirmationToken怎么用?C# UserManager.GenerateEmailConfirmationToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserManager
的用法示例。
在下文中一共展示了UserManager.GenerateEmailConfirmationToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public ActionResult Register(RegisteredUser newUser)
{
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
{
UserLockoutEnabledByDefault = true,
DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
MaxFailedAccessAttemptsBeforeLockout = 3
};
var identityUser = new IdentityUser()
{
UserName = newUser.UserName,
Email = newUser.Email
};
IdentityResult result = manager.Create(identityUser, newUser.Password);
if (result.Succeeded)
{
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Home",
new { userId = identityUser.Id, code = code },
protocol: Request.Url.Scheme);
string email = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
ViewBag.FakeConfirmation = email;
}
return View();
}
示例2: Register
public ActionResult Register(RegisteredUser newUser)
{
// TAKING THE WRONG MODEL AS INPUT???
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
{
UserLockoutEnabledByDefault = true,
DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
MaxFailedAccessAttemptsBeforeLockout = 3
};
var identityUser = new IdentityUser()
{
UserName = newUser.UserName,
Email = newUser.Email
};
// this threw an error, but it also worked so what gives???
IdentityResult result = manager.Create(identityUser, newUser.Password);
if (result.Succeeded)
{
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
// identityUser.Id use this to create an entry in our accounts table
var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
var callbackUrl = Url.Action("VerifiedEmail", "Accounts",
new { userId = identityUser.Id, code = code },
protocol: Request.Url.Scheme);
string email = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
ViewBag.FakeConfirmation = email;
UserAccountVMRepo uaRepo = new UserAccountVMRepo();
uaRepo.CreateAccount(newUser.FirstName, newUser.LastName, identityUser.Id);
// CREATE WITH CONSUMER ROLE BY DEFAULT
SecurityEntities context = new SecurityEntities();
AspNetUser user = context.AspNetUsers
.Where(u => u.UserName == newUser.UserName).FirstOrDefault();
AspNetRole role = context.AspNetRoles
.Where(r => r.Name == "consumer").FirstOrDefault();
user.AspNetRoles.Add(role);
context.SaveChanges();
MailHelper mailer = new MailHelper();
string response = mailer.EmailFromArvixe(
new RegisteredUser(newUser.Email, newUser.Subject = "Confirm Email", newUser.Body = email));
ViewBag.Response = response;
return View("ConfirmEmail");
}
return View();
}
示例3: sendConfirmationEmail
private void sendConfirmationEmail(User user)
{
var provider = new MachineKeyProtectionProvider();
UserManager<User, int> um = new UserManager<User, int>(ur);
um.UserTokenProvider = new DataProtectorTokenProvider<User, int>(provider.Create("EmailConfirmation"));
um.EmailService = new EmailService();
TempData.Add("confirmEmail", "Le hemos enviado un correo electrónico para confirmar su cuenta, comprube la carpeta spam");
if (Url != null)
{
var code = um.GenerateEmailConfirmationToken(user.U_id);
var callbackUrl = Url.Action(
"ConfirmEmail", "Home",
new { userId = user.Id, code = code },
protocol: "http");
um.SendEmail(user.Id,
"Confirma tu correo",
"Por favor confirme su correo haciendo click en este <a href=\""
+ callbackUrl + "\">link</a>");
}
}
示例4: Register
public ActionResult Register(RegisteredUser newUser)
{
CaptchaHelper captchaHelper = new CaptchaHelper();
string captchaResponse = captchaHelper.CheckRecaptcha();
if (captchaResponse != "Valid")
{
ViewBag.ErrorResponse = "The captcha must be valid";
return View();
}
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
{
UserLockoutEnabledByDefault = true,
DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
MaxFailedAccessAttemptsBeforeLockout = 3
};
var identityUser = new IdentityUser()
{
UserName = newUser.UserName,
Email = newUser.Email
};
IdentityResult result = manager.Create(identityUser, newUser.Password);
if (result.Succeeded)
{
if (newUser.UserRole.Equals("Buyer") || newUser.UserRole.Equals("Farm"))
{
//Taking the username on the account successful creation and applying it to the
//Farm database to create a Farm table with that username under the 'farmName' field.
AccountRepo accountRepo = new AccountRepo();
accountRepo.InitializeUserAccount(newUser);
}
var authenticationManager
= HttpContext.Request.GetOwinContext().Authentication;
var userIdentity = manager.CreateIdentity(identityUser,
DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { },
userIdentity);
string testVariable = newUser.UserRole;
AddUserToRole(newUser.UserName, newUser.UserRole);
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Home",
new { userId = identityUser.Id, code = code },
protocol: Request.Url.Scheme);
string emailMessage = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
string response = new MailHelper().EmailFromArvixe(new ViewModels.Message(newUser.Email, emailMessage));
ViewBag.ConfirmationResponse = response;
TempData["ConfirmationResponse"] = "You have successfully registered for an account. Please verify your account by clicking on the link sent to you in your e-mail.";
return RedirectToAction("Login");
}
ViewBag.ErrorResponse = "There was an error with the input provided";
return View();
}
示例5: Register
public ActionResult Register(RegisteredUser newUser)
{
//when user registers in checks model requirements to ensure valid input
if (ModelState.IsValid)
{
CaptchaHelper captchaHelper = new CaptchaHelper();
string captchaResponse = captchaHelper.CheckRecaptcha();
ViewBag.CaptchaResponse = captchaResponse;
// add user to database, lock account until email confirmation
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
{
//set account to lock after consecutive failed login attempts
UserLockoutEnabledByDefault = true,
DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
MaxFailedAccessAttemptsBeforeLockout = 3
};
var identityUser = new IdentityUser()
{
UserName = newUser.UserName,
Email = newUser.Email
};
IdentityResult result = manager.Create(identityUser, newUser.Password);
if (result.Succeeded)
{
samUserRegEntities context = new samUserRegEntities();
AspNetUser user = context.AspNetUsers
.Where(u => u.UserName == newUser.UserName).FirstOrDefault();
AspNetRole role = context.AspNetRoles
.Where(r => r.Name == "registered").FirstOrDefault();
user.AspNetRoles.Add(role);
context.SaveChanges();
//creates token to be passed to mail helper to allow email confirmation
CreateToken ct = new CreateToken();
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Home",
new { userId = identityUser.Id, code = code },
protocol: Request.Url.Scheme);
//send callbackURL to email helper
MailHelper mailer = new MailHelper();
string email = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
string subject = "Please confirm your email";
//try
//{
mailer.EmailFromArvixe(email, identityUser.Email, subject);
ViewBag.FakeConfirmation =
"An account confirmation has been sent to your email, please confirm before attempting to login";
//}
//catch (System.Exception ex)
//{
// ViewBag.FakeConfirmation = ex.Message;
//}
}
}
return View();
}
示例6: Register
public ActionResult Register(RegisteredUser newUser)
{
CaptchaHelper captchaHelper = new CaptchaHelper();
string captchaResponse = captchaHelper.CheckRecaptcha();
ViewBag.CaptchaResponse = captchaResponse;
TempData["captcha"] = captchaResponse;
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
{
UserLockoutEnabledByDefault = true,
DefaultAccountLockoutTimeSpan = new System.TimeSpan(0, 10, 0),
MaxFailedAccessAttemptsBeforeLockout = 3
};
var identityUser = new IdentityUser()
{
UserName = newUser.UserName,
Email = newUser.Email
};
IdentityResult result = manager.Create(identityUser, newUser.Password);
if (result.Succeeded && captchaResponse == VALID_CAPTCHA)
{
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Home",
new { userId = identityUser.Id, code = code },
protocol: Request.Url.Scheme);
string email = "<h3>Please confirm your account by clicking this link:</h3><a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
MailHelper mailer = new MailHelper();
string response = mailer.EmailFromArvixe(newUser, email);
ViewBag.Response = response;
TempData["response"] = response;
}
return RedirectToAction("Index","Home");
}
示例7: Register
public ActionResult Register(RegisteredUser newUser) {
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
{
UserLockoutEnabledByDefault = true,
DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
MaxFailedAccessAttemptsBeforeLockout = 3
};
var identityUser = new IdentityUser() { UserName = newUser.UserName,
Email = newUser.Email };
IdentityResult result = manager.Create(identityUser, newUser.Password);
if (result.Succeeded) {
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account",
new { userId = identityUser.Id, code = code },
protocol: Request.Url.Scheme);
string link = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
newUser.ConfirmLink = link;
// sending Email Start
MailHelper mailer = new MailHelper();
string response = mailer.EmailFromArvixe(
new RegisteredUser(newUser.Email, newUser.UserName,newUser.ConfirmLink ));
if (response != "Failure sending mail."){
ViewBag.Success = response;
}else{
ViewBag.Failure = response;
}
// sending Email End
}
return View();
}
示例8: CompleteInfo
public ActionResult CompleteInfo(ClientInterestViewModel client)
{
repo.saveClientInfo(client);
var userStore = new UserStore<IdentityUser>();
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
CreateTokenProvider(manager, EMAIL_CONFIRMATION);
var user = manager.FindByName(client.userName);
var code = manager.GenerateEmailConfirmationToken(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Home",
new { userId = user.Id, code = code },
protocol: Request.Url.Scheme);
string emailBody = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">Confirm Registration</a>";
MailHelper mailer = new MailHelper();
string Subject = "Confirm registration";
string response = mailer.EmailFromArvixe(
new Message(client.email, Subject, emailBody));
if (response.IndexOf("Success") >= 0)
{
// ViewBag.Message = "A confirm email has been sent. Please check your email.";
TempData["Message"] = "A confirm email has been sent. Please check your email.";
return RedirectToAction("CompleteRegistration");
}
else {
ViewBag.Message = response;
}
ClientInterestViewModel newClient = repo.getClientInterest(client.userId);
return View(newClient);
// return RedirectToAction("UserProfile", new { userName = client.userName});
}