本文整理汇总了C#中IdentitySample.Models.ApplicationUser类的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUser类的具体用法?C# ApplicationUser怎么用?C# ApplicationUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationUser类属于IdentitySample.Models命名空间,在下文中一共展示了ApplicationUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
//lsakdjf ls
public async Task<bool> Register(string email, int? schoolid, int instructorid, string password)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = email, Email = email };
user.SchoolIdentity = schoolid;
user.InstructorIdentity = instructorid;
// user.SchoolID = model.SchoolID;
var result = await UserManager.CreateAsync(user, password);
var role = new IdentityRole("Instructor");
var result2 = UserManager.AddToRole(user.Id, role.Name);
if (result.Succeeded && result2.Succeeded)
{
var 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", " UserName / Email = " + email + "\n Password : " + password + "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
return true;
}
else
return false;
}
else
return false;
}
示例2: Create
public async Task<ActionResult> Create(RegisterDoctorViewModel userViewModel)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { FirstName = userViewModel.FirstName, LastName = userViewModel.LastName, PWZ = userViewModel.PWZ, UserName = userViewModel.Email, Email = userViewModel.Email, IsConfirmed = true };
var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);
if (adminresult.Succeeded)
{
var result = await UserManager.AddToRoleAsync(user.Id, "Doctor");
if (!result.Succeeded)
{
ModelState.AddModelError("", result.Errors.First());
return View();
}
}
else
{
ModelState.AddModelError("", adminresult.Errors.First());
return View();
}
return RedirectToAction("Index");
}
return View();
}
示例3: Get
// GET: api/Claims
//public IEnumerable<string> Get()
public ApplicationUser Get()
{
//return new string[] { "value1", "value2" };
var u = new ApplicationUser();
u.UserName = "jopa";
return u;
}
示例4: VerifyClientIdAsync
private static Task<bool> VerifyClientIdAsync(ApplicationUserManager manager, ApplicationUser user, CookieValidateIdentityContext context)
{
string clientId = context.Identity.FindFirstValue("AspNet.Identity.ClientId");
if (!string.IsNullOrEmpty(clientId) && user.Clients.Any(c => c.Id.ToString() == clientId))
{
user.CurrentClientId = clientId;
return Task.FromResult(true);
}
return Task.FromResult(false);
}
示例5: RegisterUser
/// <summary>
/// This method registers a Beagle Tag User.
/// </summary>
/// <param name="email"></param>
/// <param name="password"></param>
/// <returns></returns>
public async Task<JsonResult> RegisterUser(string email, string password)
{
if (email == null || password == null)
{
return Json(new
{
success = false,
message = "missing one or more parameters",
UID = "",
}, JsonRequestBehavior.AllowGet);
}
bool success = false;
string message = "";
var roles = new List<string> { "Admin" };
//create a new user for this person
var user = new ApplicationUser { UserName = email, Email = email, Tags = new List<IdentitySample.Models.Tag>(), Roles = roles };
var UserManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
var result = await UserManager.CreateAsync(user, password);
if (result.Succeeded)
{
success = true;
}
else
{
message = "failed due to these errors: " + result.Errors.ToList().ToString();
}
//await ZDB.Users.UpdateOneAsync(x => x.Email == email, Builders<ApplicationUser>.Update.Push(x => x.Roles, "Admin"));
var idString = "";
if(user!= null)
{
idString = user.Id.ToString();
}
return Json(new
{
success = success,
message = message,
UID = idString
}, JsonRequestBehavior.AllowGet);
}
示例6: 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)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例7: CreateAdminUser
/// <summary>
/// Creates a store manager user who can manage the inventory.
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
private static async Task CreateAdminUser(IServiceProvider serviceProvider)
{
var options = serviceProvider.GetRequiredService<IOptions<IdentityDbContextOptions>>().Value;
const string adminRole = "Administrator";
var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
if (!await roleManager.RoleExistsAsync(adminRole))
{
await roleManager.CreateAsync(new IdentityRole(adminRole));
}
var user = await userManager.FindByNameAsync(options.DefaultAdminUserName);
if (user == null)
{
user = new ApplicationUser { UserName = options.DefaultAdminUserName };
await userManager.CreateAsync(user, options.DefaultAdminPassword);
await userManager.AddToRoleAsync(user, adminRole);
await userManager.AddClaimAsync(user, new Claim("ManageStore", "Allowed"));
}
}
示例8: Register
public async Task<ActionResult> Register(RegisterPatientViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { FirstName = model.FirstName, LastName = model.LastName, Pesel = model.Pesel, Address = model.Address, UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var roleResult = await UserManager.AddToRoleAsync(user.Id, "Patient");
if (roleResult.Succeeded)
{
return View("RegistrationMessage");
}
else
{
ModelState.AddModelError("", roleResult.Errors.First());
}
}
ModelState.AddModelError("", result.Errors.First());
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例9: Register
public async Task<HttpResponseMessage> Register([FromBody]dynamic model)
{
var user = new ApplicationUser { UserName = (string)model.username, Email = (string)model.email };
var result = await Manager().CreateAsync(user, (string)model.password);
if (!result.Succeeded)
{
return Request.CreateErrorResponse(HttpStatusCode.MethodNotAllowed, JsonConvert.SerializeObject(result.Errors));
}
if (model.claims != null)
{
var claims = JsonConvert.DeserializeObject<Dictionary<string, string>>(model.claims.ToString());
if (claims.Count > 0)
{
AddClaims(user.Id, claims);
}
}
return new HttpResponseMessage
{
Content = new StringContent(JsonConvert.SerializeObject(await Manager().FindByIdAsync(user.Id))),
StatusCode = HttpStatusCode.Created
};
}
示例10: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Company = model.Company };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
String body = IdentitySample.Common.Helper.Build_UserRegistration(user.UserName, callbackUrl);
await UserManager.SendEmailAsync(user.Id, "Confirmación de cuenta", body);
return View("DisplayEmail");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例11: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
//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>");
string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");
ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
+ "before you can log in.";
return View("DisplayEmail");
//return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例12: RegisterStudentForSection
public async Task<ActionResult> RegisterStudentForSection(RegisterViewModelOfStudentToSection model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
Student stud = new Student();
stud.Age = model.age;
stud.Gender = model.Gender;
stud.schoolName = model.schoolName;
stud.Id = user.Id;
stud.SectionId = model.SectionId;
db.Students.Add(stud);
db.SaveChanges();
result = await UserManager.AddToRolesAsync(user.Id, "Student");
if (!result.Succeeded)
{
}
else {
var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
ViewBag.Link = callbackUrl;
return RedirectToAction("StudentManagement", "Teachers",new { id=model.SectionId});
}
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例13: RegisterTeacher
public async Task<ActionResult> RegisterTeacher(RegisterViewModelOfTeacher model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
Teacher teac = new Teacher();
teac.Address = model.Address;
teac.School = model.School;
teac.UserId = user.Id;
db.Teachers.Add(teac);
db.SaveChanges();
result = await UserManager.AddToRolesAsync(user.Id, "Teacher");
if (!result.Succeeded)
{
}
else {
var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
ViewBag.Link = callbackUrl;
return View("DisplayEmail");
}
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例14: SignInAsync
private async Task SignInAsync(ApplicationUser user, bool isPersistent, bool rememberBrowser)
{
// Clear any partial cookies from external or two factor partial sign ins
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
var userIdentity = await user.GenerateUserIdentityAsync(UserManager);
if (rememberBrowser)
{
var rememberBrowserIdentity = AuthenticationManager.CreateTwoFactorRememberBrowserIdentity(user.Id);
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, userIdentity, rememberBrowserIdentity);
}
else
{
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, userIdentity);
}
}
示例15: SignInAsync
private async Task SignInAsync(ApplicationUser user, bool isPersistent)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}