当前位置: 首页>>代码示例>>C#>>正文


C# Models.ApplicationUser类代码示例

本文整理汇总了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;
        }
开发者ID:xanga4444,项目名称:gurukul-yomari-,代码行数:32,代码来源:InstructorsController.cs

示例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();
        }
开发者ID:JohnnyDablju,项目名称:Clinic,代码行数:25,代码来源:DoctorsController.cs

示例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;
 }
开发者ID:geandbe,项目名称:ASPIdentity,代码行数:9,代码来源:ClaimsController.cs

示例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);
        }
开发者ID:GabrielSchimidtMylla,项目名称:IdentityFeatures,代码行数:11,代码来源:ApplicationCookieIdentityValidator.cs

示例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);
        }
开发者ID:jmaag,项目名称:BeagleCloud,代码行数:52,代码来源:RegisterController.cs

示例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);
        }
开发者ID:jwuwork,项目名称:IdentitySample,代码行数:20,代码来源:AccountController.cs

示例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"));
            }
        }
开发者ID:491134648,项目名称:Identity,代码行数:26,代码来源:SampleData.cs

示例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);
        }
开发者ID:JohnnyDablju,项目名称:Clinic,代码行数:24,代码来源:AccountController.cs

示例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
            };
        }
开发者ID:geandbe,项目名称:ASPIdentity,代码行数:24,代码来源:UsersController.cs

示例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);
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:23,代码来源:AccountController.cs

示例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);
        }
开发者ID:Nitemare1313,项目名称:MovieStore,代码行数:31,代码来源:AccountController.cs

示例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);
        }
开发者ID:zhaokk,项目名称:ChildProgramming,代码行数:37,代码来源:AccountController.cs

示例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);
        }
开发者ID:zhaokk,项目名称:ChildProgramming,代码行数:34,代码来源:AccountController.cs

示例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);
     }
 }
开发者ID:venkat0708,项目名称:MovieBooking,代码行数:15,代码来源:AccountController.cs

示例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);
 }
开发者ID:jwuwork,项目名称:IdentitySample,代码行数:6,代码来源:AccountController.cs


注:本文中的IdentitySample.Models.ApplicationUser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。