本文整理汇总了C#中RegisterViewModel类的典型用法代码示例。如果您正苦于以下问题:C# RegisterViewModel类的具体用法?C# RegisterViewModel怎么用?C# RegisterViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegisterViewModel类属于命名空间,在下文中一共展示了RegisterViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public async Task<ActionResult> Create(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var succeded = true;
var user = new CustomUser { UserName = model.Email, Email = model.Email };
var adminresult = await UserManager.CreateAsync(user, model.Password);
if (!adminresult.Succeeded)
{
ModelState.AddModelError("", adminresult.Errors.First());
}
else
{
user = await UserManager.FindByEmailAsync(model.Email);
var result = await UserManager.AddToCategoryAsync(user.Id, model.Category);
if (!result.Succeeded)
{
ModelState.AddModelError("", result.Errors.First());
}
else
{
return RedirectToAction("Index");
}
}
}
model.CategoriesList = new SelectList(await CategoryManager.Categories.ToListAsync(), "Name", "Name");
return View(model);
}
示例2: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
var userValidator = UserManager.UserValidator as UserValidator<ApplicationUser>;
userValidator.AllowOnlyAlphanumericUserNames = false; //not sure why these two lines work, but I can now use @symbol in username allowing for emails as userName.
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, SuggestedAccount = model.SuggestedAccount, GradeLevel = model.GradeLevel};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
UserManager.AddToRole(user.Id, model.SuggestedAccount);
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例3: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
try
{
// Create a profile, password, and link the local login before signing in the user
User user = new User(model.UserName);
if (await IdentityStore.CreateLocalUser(user, model.Password))
{
await AuthenticationManager.SignIn(HttpContext, user.Id, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Failed to register user name: " + model.UserName);
}
}
catch (IdentityException e)
{
ModelState.AddModelError("", e.Message);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例4: Register
public async Task<IActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
TimeZoneId = _generalSettings.Value.DefaultTimeZone
};
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action(new UrlActionContext { Action = nameof(ConfirmEmail), Controller = "Admin", Values = new { userId = user.Id, token = token }, Protocol = Request.Scheme });
await _mediator.SendAsync(new SendConfirmAccountEmail { Email = model.Email, CallbackUrl = callbackUrl });
return RedirectToAction(nameof(DisplayEmail), "Admin");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例5: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
OglasController aleksaoglas = new OglasController();
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
var korisnik = new Korisnik() { IDKorisnik = user.Id, eMail = user.UserName, MailStize = 0 };
aleksaoglas.baza.Korisnik.Add(korisnik);
aleksaoglas.baza.SaveChanges();
return RedirectToAction("Login", "Account");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例6: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
// Create a local login before signing in the user
var user = new ApplicationUser()
{
UserName = model.UserName,
DisplayName = model.DisplayName,
FacebookProfile = model.FacebookProfile,
};
var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
if (result.Success)
{
await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例7: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new MailPigUser
{
UserName = model.Email,
Email = model.Email,
Oib = model.Oib,
UsedForCommercialPurposes = model.UsedForCommercialPurposes,
OrganisationName = model.OrganisationName
};
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Index", "Dashboard");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例8: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
if (await RecaptchaIsValid(Request.Form["g-recaptcha-response"]))
//if(true)
{
var user = new ApplicationUser() { UserName = model.UserName };
var result = UserManager.Create(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
ModelState.AddModelError(
"invalid-recaptcha-response",
"Please answer the recaptcha challenge.");
}
return View();
}
示例9: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
UserService.AddUser(new User
{
FirstName = model.FirstName,
LastName = model.LastName,
Username = model.UserName,
Password = UserManager.PasswordHasher.HashPassword(model.Password),
Email = model.EmailAddress,
IsAdmin = false
});
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Home", "User");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例10: Register
public ActionResult Register(RegisterViewModel model)
{
if (!ModelState.IsValid)
return Json(new ServiceOperationResult(false, Main.InvalidForm), JsonRequestBehavior.AllowGet);
return Json(PiServices.UserService.AddUser(model), JsonRequestBehavior.AllowGet);
}
示例11: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
user.Email = model.Email;
user.ConfirmedEmail = false;
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress("[email protected]", "Web Registration"),
new System.Net.Mail.MailAddress(user.Email));
m.Subject = "Email confirmation";
m.Body = string.Format("Dear {0}<BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>", user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));
m.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mydomain.com");
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
smtp.EnableSsl = true;
smtp.Send(m);
return RedirectToAction("Confirm", "Account", new { Email = user.Email });
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例12: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
// Create a local login before signing in the user
var user = new ApplicationUser
{
UserName = model.UserName,
FirstName = model.FirstName,
LastName = model.LastName,
Email = model.Email,
PhotoUrl = (model.Photo ?? @"../../img/Avatars/default-avatar.jpg")
};
var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
if (result.Success)
{
await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例13: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new User()
{
UserName = model.UserName,
FirstName = model.FirstName,
LastName = model.LastName,
Email = model.Email,
Phone = model.Phone,
CellPhone = model.CellPhone,
Gender = model.Gender,
Birthday = model.Birthday,
Address = model.Address,
CreationDate = DateTime.UtcNow.AddHours(-5)
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
return View(model);
}
示例14: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
CreateResponse response = await this.Membership.CreateAsync(new CreateRequest()
{
UserName = model.UserName,
Password = model.Password,
AuthenticationType = DataContract.AuthenticationTypeEnum.ApplicationCookie
});
if (response.Success)
{
ClaimsIdentity identity = response.ClaimIdentity.ConvertToClaimsIdentity();
SignInAsync(identity, IsPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(response.Errors);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例15: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (model.UserName.Length > 16 || model.UserName.Length < 6)
{
ModelState.AddModelError("UserName", "The username should be between 6 and 16 characters long.");
}
if (ModelState.IsValid)
{
// Create a local login before signing in the user
var user = new ApplicationUser { UserName = model.UserName, Points = 10};
var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
if (result.Success)
{
await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}