示例#1
0
        public ActionResult Register(RegisterViewModel user)
        {
            if (ModelState.IsValid == false)
            {
                return(View(user));
            }
            IdentityResult result = accountAppService.Register(user);

            if (result.Succeeded)
            {
                CartAppService         cartAppService = new CartAppService();
                IAuthenticationManager owinMAnager    = HttpContext.GetOwinContext().Authentication;
                //SignIn
                SignInManager <ApplicationUserIdentity, string> signinmanager =
                    new SignInManager <ApplicationUserIdentity, string>(
                        new ApplicationUserManager(), owinMAnager
                        );
                ApplicationUserIdentity identityUser = accountAppService.Find(user.UserName, user.PasswordHash);
                signinmanager.SignIn(identityUser, true, true);

                /*
                 * var userSignIn = User.Identity.GetUserId();
                 * cartAppService.InsertCart(userSignIn);
                 */
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(user));
            }
        }
示例#2
0
        public void Register_test()
        {
            RegisterViewModel user = new RegisterViewModel {
                UserName = "******", PasswordHash = "123456789", Email = "*****@*****.**"
            };
            var result = account.Register(user);

            Assert.That(result.Succeeded, Is.EqualTo(true));//because the user is exist already
        }
示例#3
0
        public async Task <IActionResult> Register(RegisterAccountDTO registerAccountDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            bool isUsernameExist = await _accountAppService.checkUsernameExist(registerAccountDTO.UserName);

            if (isUsernameExist)
            {
                return(BadRequest(new Response {
                    Message = "Username already exist"
                }));
            }
            bool isEmailExist = await _accountAppService.checkEmailExist(registerAccountDTO.Email);

            if (isEmailExist)
            {
                return(BadRequest(new Response {
                    Message = "Email already exist"
                }));
            }
            try
            {
                registerAccountDTO.IsDoctor = false;
                ApplicationUserIdentity registerUser = await _accountAppService.Register(registerAccountDTO);

                await _accountAppService.AssignToRole(registerUser.Id, UserRoles.Patient);

                _generalAppService.CommitTransaction();
                return(Ok(new Response {
                    Message = "Account created successfully"
                }));
            }
            catch (Exception ex)
            {
                _generalAppService.RollbackTransaction();
                return(BadRequest(new Response {
                    Message = ex.Message
                }));
            }
        }
示例#4
0
        public async Task <JsonResult> Register(RegisterViewModel model)
        {
            var res = await _accountAppService.Register(new RegisterInput()
            {
                Username = model.AoxiangUsername, Password = model.AoxiangPassword
            });

            await _notificationPublisher.PublishAsync(NotificationName.CheckProfile,
                                                      new MessageNotificationData(Url.Action("UserProfile", "User")),
                                                      userIds : new[] { new UserIdentifier(AppConsts.DefaultTenant, res.First) });

            return(Json(new AjaxResponse(res.Second)));
        }
示例#5
0
        public ActionResult Register(RegisterVM user)
        {
            if (ModelState.IsValid == false)
            {
                return(View(user));
            }
            IdentityResult result = accountAppService.Register(user);

            if (result.Succeeded)
            {
                IAuthenticationManager owinMAnager = HttpContext.GetOwinContext().Authentication;
                //SignIn
                SignInManager <ApplicationUserIdentity, string> signinmanager =
                    new SignInManager <ApplicationUserIdentity, string>(
                        new ApplicationUserManager(), owinMAnager
                        );
                ApplicationUserIdentity identityUser = accountAppService.Find(user.UserName, user.PasswordHash);

                accountAppService.AssignToRole(identityUser.Id, "Dealer"); //Add user to Role


                dealerAppService.SaveNewDealer(new DAL.Dealer {
                    Id = identityUser.Id,
                });                                                                          //To add UserId to Dealer table, like make the relatin manwal

                notificationAppService.SaveNewNotification(new Notification {
                    Id = identityUser.Id, MessageNotification = 0
                });                                                                                                             //To add UserId to Notification table, like make the relatin manwal

                signinmanager.SignIn(identityUser, true, true);
                return(RedirectToAction("Index", "Car", new { area = "Dealer" }));//Dealer area
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(user));
            }
        }
示例#6
0
        public ActionResult Register(RegisterViewModel newUser, bool isHost = false)
        {
            if (!ModelState.IsValid)
            {
                return(View(newUser));
            }
            IdentityResult result = accountAppService.Register(newUser, isHost, User.IsInRole("Admin"));

            if (result.Succeeded)
            {
                ApplicationIdentityUser registeredUser = accountAppService.Find(newUser.UserName, newUser.PasswordHash);

                if (User.IsInRole("Admin"))
                {
                    accountAppService.AssignToRole(registeredUser.Id, "Admin");
                }
                else
                {
                    if (isHost)
                    {
                        accountAppService.AssignToRole(registeredUser.Id, "Host");
                    }
                    else
                    {
                        accountAppService.AssignToRole(registeredUser.Id, "User");
                        ShoppingCartAppService.Insert(registeredUser.Id);
                    }
                }
                return(RedirectToAction("Login"));
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(newUser));
            }
        }