コード例 #1
0
        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);

                    // For more information on how to enable account confirmation and password reset please visit https://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>");

                    var service = new UserAccountService(HttpContext.GetOwinContext().Get <ApplicationDbContext>());
                    service.CreateUserAccount(model.FirstName, model.LastName, user.Id);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        protected override void Seed(ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            if (!context.Users.Any(t => t.UserName == "*****@*****.**"))
            {
                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                userManager.Create(user, "Password!2");

                var service = new UserAccountService(context);
                service.CreateUserAccount("admin", "adminson", user.Id);

                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole {
                    Name = "Admin"
                });
                context.SaveChanges(); // save changes to db to save role for following role asignment

                userManager.AddToRole(user.Id, "Admin");
            }

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }
コード例 #3
0
        public ConsolidatedUserInformationResponseModel CreateConsolidatedUser([FromBody] JObject jmodel)
        {
            var Model = new ConsolidatedUserInformationInputModel()
            {
                UserAccount = jmodel["user"].ToObject <UserAccountModel>(),
                UserAddress = jmodel["address"].ToObject <UserAddressModel>(),
                ContactInfo = jmodel["contactInfo"].ToObject <ContactInfoModel>(),
                Interests   = jmodel["interests"].ToObject <List <InterestModel> >()
            };

            Model.UserAccount = UserAccountService.CreateUserAccount(Model.UserAccount);
            Model.UserAddress = AddressService.CreateUserAddress(Model.UserAddress);
            Model.ContactInfo.UserAccountId = Model.UserAccount.Id;
            Model.ContactInfo.UserAddressId = Model.UserAddress.Id;
            Model.ContactInfo = ContactInfoService.CreateUserContactInfo(Model.ContactInfo);

            if (Model.Interests != null)
            {
                foreach (var Interest in Model.Interests)
                {
                    var NewMapping = new InterestUserMapModel
                    {
                        UserAccountId = Model.UserAccount.Id,
                        InterestId    = Interest.Id
                    };

                    InterestService.CreateInterestUserMap(NewMapping);
                }
            }

            Model.Interests = InterestService.GetUserInterests(Model.UserAccount.Id);

            return(TransformHelpers.UserInputModelToUserResponseModel(Model));
        }
コード例 #4
0
        public void OnGet()
        {
            _useraccount.Username = "******";
            _useraccount.Password = "******";

            UserConfirmation  = _useraccountservice.CreateUserAccount(_useraccount.Username, _useraccount.Password);
            EmailConfirmation = _googlemailservice.CreateMailAccount(_useraccount.Username);
        }
コード例 #5
0
        public void OnGet()
        {
            _useraccount.Username = "******";
            _useraccount.Password = "******";

            UserConfirmation  = _useraccountservice.CreateUserAccount(_useraccount.Username, _useraccount.Password);
            EmailConfirmation = _outlookmailservice.CreateMailAccount(_useraccount.Username);
        }
コード例 #6
0
        public void OnGet()
        {
            _useraccount.Username = "******";
            _useraccount.Password = "******";

            UserConfirmation = _useraccountservice.CreateUserAccount(_useraccount.Username, _useraccount.Password);

            GoogleMailService googleMailService = new GoogleMailService();
            IndexModel3       indexModel3       = new IndexModel3(googleMailService);

            EmailConfirmation = indexModel3.CreateNewEmail(_useraccount.Username);
        }
コード例 #7
0
        public void OnGet()
        {
            _useraccount.Username = "******";
            _useraccount.Password = "******";

            UserConfirmation = _useraccountservice.CreateUserAccount(_useraccount.Username, _useraccount.Password);

            GoogleMailService googleMailService = new GoogleMailService();
            IndexModel5       indexModel5       = new IndexModel5();

            EmailConfirmation = indexModel5.CreateNewEmail(googleMailService, _useraccount.Username);
        }
コード例 #8
0
        public void OnGet()
        {
            _useraccount.Username = "******";
            _useraccount.Password = "******";

            UserConfirmation = _useraccountservice.CreateUserAccount(_useraccount.Username, _useraccount.Password);

            GoogleMailService googleMailService = new GoogleMailService();

            EmailService      = googleMailService;
            EmailConfirmation = EmailService.CreateMailAccount(_useraccount.Username);
        }
コード例 #9
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email, Id = model.Id
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.FirstName));

            var service = new UserAccountService(HttpContext.Current.GetOwinContext().GetUserManager <ApplicationDbContext>());

            service.CreateUserAccount(model.FirstName, model.LastName, (decimal)model.Mobile, model.Gender, user.Id);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
コード例 #10
0
        protected override void Seed(TrackMyMoney.Models.ApplicationDbContext context)
        {
            // The below code is written for making an Account for Admin if it does not exist.
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            if (!context.Users.Any(t => t.UserName == "*****@*****.**"))
            {
                var user = new ApplicationUser {
                    Id = "123", UserName = "******", Email = "*****@*****.**"
                };                                     // Admin username and email.
                userManager.Create(user, "Admin@123"); // Admin Password

                var service = new UserAccountService(context);
                service.CreateUserAccount("admin", "user", (decimal)1111111111, UserAccount.Genders.Male, user.Id);

                context.Roles.AddOrUpdate(r => r.Name, new IdentityRole {
                    Name = "Admin"
                });
                context.SaveChanges();

                userManager.AddToRole(user.Id, "Admin");
            }
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
コード例 #11
0
 public UserAccountViewModel CreateUser(UserAccountModel inputModel)
 {
     return(TransformHelpers.ModelToUserAccountViewModel(UserAccountService.CreateUserAccount(inputModel)));
 }