本文整理汇总了C#中RegisterViewModel类的典型用法代码示例。如果您正苦于以下问题:C# RegisterViewModel类的具体用法?C# RegisterViewModel怎么用?C# RegisterViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegisterViewModel类属于命名空间,在下文中一共展示了RegisterViewModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Dragan89,项目名称:IdentityFrameworkExtender,代码行数:29,代码来源:UserAdminController.cs
示例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);
}
开发者ID:naomish,项目名称:PracticeCsharp,代码行数:26,代码来源:AccountController.cs
示例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);
}
开发者ID:KuduApps,项目名称:PreviewMvc5,代码行数:27,代码来源:AccountController.cs
示例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);
}
开发者ID:nicolastarzia,项目名称:allReady,代码行数:26,代码来源:AdminController.cs
示例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);
}
开发者ID:aleksa93,项目名称:milos,代码行数:30,代码来源:AccountController.cs
示例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);
}
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:26,代码来源:AccountController.cs
示例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);
}
开发者ID:cybermv,项目名称:MailPig,代码行数:34,代码来源:AccountController.cs
示例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();
}
开发者ID:softwareTM,项目名称:PraktikaMusicStoreWebsite,代码行数:26,代码来源:AccountController.cs
示例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);
}
开发者ID:vanhouc,项目名称:QuizBuilderASP,代码行数:29,代码来源:UserController.cs
示例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);
}
开发者ID:jacbar,项目名称:Runner,代码行数:7,代码来源:AccountController.cs
示例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);
}
开发者ID:chung1991,项目名称:webenterprise,代码行数:31,代码来源:AccountController.cs
示例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);
}
开发者ID:viruslivia,项目名称:PikemanForum,代码行数:28,代码来源:AccountController.cs
示例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);
}
开发者ID:jdnichollsc,项目名称:Javascript-Games,代码行数:32,代码来源:AccountController.cs
示例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);
}
开发者ID:BogamSushil,项目名称:BaseLine,代码行数:26,代码来源:AccountController.cs
示例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);
}
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:26,代码来源:AccountController.cs
示例16: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
user.HomeTown = model.HomeTown;
user.MyUserInfo = new MyUserInfo() { FirstName = model.UserName };
// Store Gender as Claim
user.Claims.Add(new IdentityUserClaim() { ClaimType = ClaimTypes.Gender, ClaimValue = "Male" });
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
开发者ID:RammohanKareti,项目名称:Mocking-Identity-EntityFramework,代码行数:27,代码来源:AccountController.cs
示例17: 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)
{
if (user.Roles.Count == 0)
{
UserManager.AddToRole(user.Id, "User");
}
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
开发者ID:DMU-CTEC2902,项目名称:LC-TeamFlash,代码行数:26,代码来源:AccountController.cs
示例18: Create
public async Task<ActionResult> Create(RegisterViewModel userViewModel, params string[] selectedRoles)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = userViewModel.Email, Email = userViewModel.Email, NickName = userViewModel.NickName };
var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);
if (adminresult.Succeeded)
{
if (selectedRoles != null)
{
var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles);
if (!result.Succeeded)
{
ModelState.AddModelError("", result.Errors.First());
ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");
return View();
}
}
}
else
{
ModelState.AddModelError("", adminresult.Errors.First());
ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
return View();
}
return RedirectToAction("Index");
}
ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
return View();
}
开发者ID:david545,项目名称:BooksShoppingCart,代码行数:31,代码来源:UsersController.cs
示例19: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
user.UserInfo = new ApplicationUserInfo { ApplicationUser = user };
Image defaultAvatar = new Image { Name = "defaultAvatar" };
user.UserInfo.Avatar = defaultAvatar;
db.SaveChanges();
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
db.SaveChanges();
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
开发者ID:bave8672,项目名称:ASPNETMVCBlogDemo,代码行数:26,代码来源:AccountController.cs
示例20: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
using (var context = new ApplicationDbContext())
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName, Name = model.Name, LastName = model.LastName, Status = "Active" };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
var userStore = new UserStore<ApplicationUser>(context);
var userManager = new UserManager<ApplicationUser>(userStore);
userManager.AddToRole(user.Id, "SimpleUser");
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
开发者ID:kamilzuk24,项目名称:PracaMGR-Full,代码行数:31,代码来源:AccountController.cs
注:本文中的RegisterViewModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论