Beispiel #1
0
        public async Task <IActionResult> SignUp(UserSignUpVM signUpVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(signUpVM));
            }
            var signedUp = await identityService.SignUp(signUpVM);

            if (!signedUp)
            {
                ModelState.AddModelError("Register error", "Login/Email already taken");
                return(View(signUpVM));
            }
            else
            {
                var signInVm = mapper.Map <UserSignInVM>(signUpVM);
                var signedIn = await identityService.SignIn(signInVm);

                if (signedIn)
                {
                    return(RedirectToAction(nameof(UserManagerController.Index), nameof(UserManagerController).Replace("Controller", "")));
                }
                else
                {
                    return(RedirectToAction(nameof(SignIn)));
                }
            }
        }
Beispiel #2
0
        public async Task CreateAsync(UserSignUpVM createUserVM)
        {
            var user = mapper.Map <User>(createUserVM);

            unitOfWork.DbContext.Users.Add(user);
            await unitOfWork.DbContext.SaveChangesAsync();
        }
Beispiel #3
0
        public async Task <bool> SignUp(UserSignUpVM userVm)
        {
            var user = new User
            {
                Email        = userVm.Email,
                UserName     = userVm.Login,
                RegisterDate = DateTime.Now
            };
            var res = await identityUnitOfWork.UserManager.CreateAsync(user, userVm.Password);

            return(res.Succeeded);
        }
Beispiel #4
0
        public async Task <IActionResult> SignUp(UserSignUpVM signUpVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(signUpVM));
            }
            var res = await authenticationService.SignUpAsync(signUpVM.Login, signUpVM.Password);

            if (!res)
            {
                ModelState.AddModelError("Registration error", "User already exists");
                return(View(signUpVM));
            }

            return(RedirectToAction(nameof(Home.Index), nameof(Home)));
        }
Beispiel #5
0
        public async Task <IActionResult> SignUp([FromBody] UserSignUpVM user)
        {
            var appUser = _mapper.Map <UserSignUpVM, ApplicationUser>(user);
            var result  = await _userManager.CreateAsync(appUser, user.Password);

            if (result == IdentityResult.Success)
            {
                await _singInManager.SignInAsync(appUser, false);

                var token = GenerateAccessToken(appUser);
                return(Ok(token));
            }
            else
            {
                throw new Exception("Sign-Up Failed");
            }
        }
Beispiel #6
0
        //This accepts the input from controller and add new user
        public bool RegisterUser(UserSignUpVM signUp)
        {
            bool flag = false;

            try
            {
                using (NmoorEntity db = new NmoorEntity())
                {
                    User user = new User()
                    {
                        username     = signUp.Username,
                        password     = Security.Hash(signUp.ConfirmPassword),
                        balance      = signUp.Balance,
                        status       = "Active",
                        token        = Token.TokenGenerator(),
                        email        = signUp.Email,
                        signupdate   = DateTime.Now,
                        recentsignin = DateTime.Now,
                        fullname     = signUp.FullName
                    };
                    var aUser = db.User.Any(u => u.username.Equals(user.username) && u.email.Equals(user.email));
                    if (aUser)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = true;
                        db.User.Add(user);
                        db.SaveChanges();
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
            return(flag);
        }
Beispiel #7
0
        public ActionResult Signup(UserSignUpVM user)
        {
            if (ModelState.IsValid)
            {
                account = new AccountSetUp();
                if (account.RegisterUser(user))
                {
                    ModelState.Clear();
                    ViewBag.Msg = "🥳 Account created try logging in. Happy Transactions!!!";
                }
                else
                {
                    ModelState.Clear();
                    ViewBag.Msg = "😢 Sorry account unavailable";
                }
            }

            return(View());
        }
Beispiel #8
0
        public ActionResult SignUp(UserSignUpVM model)
        {
            if (Session["User"] == null)
            {
                if (ModelState.IsValid)
                {

                    var email = db.Users.Where(e => e.email.ToLower().Equals(model.SignUpEmail.ToLower())).SingleOrDefault();
                    if (email != null)
                    {
                        ModelState.AddModelError("SignUpEmail", "Email already exists. Please enter a different Email.");
                    }
                    if (ModelState.IsValid)
                    {
                        User user = new User
                        {   
                            first_name=model.FirstName,
                            last_name=model.LastName,
                            email = model.SignUpEmail.ToLower(),
                            password = model.SignUpPassword,
                            status = true
                        };
                        db.Users.Add(user);
                        db.SaveChanges();
                        Session["User"] = user;

                        return RedirectToAction("Index", "Home");

                    }

                }

            }
            else
            {

                return RedirectToAction("Index", "Home");
            }
            UserIndex userIndexModel = new UserIndex();
            userIndexModel.signUp = model;
            ViewBag.activeTab = "signup";
            return View("Index", userIndexModel);
        }
Beispiel #9
0
        public async Task <IActionResult> SignUp([FromBody] UserSignUpVM user)
        {
            ApplicationUser appUser = _mapper.Map <UserSignUpVM, ApplicationUser>(user);

            appUser.UserName = user.Email;
            IdentityResult result = await _userManager.CreateAsync(appUser, user.Password);

            if (result == IdentityResult.Success)
            {
                await _signInManager.SignInAsync(appUser, false);

                var token = _tokenBuilder.BuildToken(appUser);
                return(Ok(token));
            }
            else
            {
                return(BadRequest("User already exists"));
            }
        }
Beispiel #10
0
        public ActionResult SignUp(UserSignUpVM model)
        {
            if (Session["User"] == null)
            {
                if (ModelState.IsValid)
                {
                    var email = db.Users.Where(e => e.email.ToLower().Equals(model.SignUpEmail.ToLower())).SingleOrDefault();
                    if (email != null)
                    {
                        ModelState.AddModelError("SignUpEmail", Resources.Resource.EmailAlreadyExistsError);
                    }
                    if (ModelState.IsValid)
                    {
                        User user = new User
                        {
                            full_name = model.full_name,
                            email     = model.SignUpEmail.ToLower(),
                            password  = model.SignUpPassword,
                            status    = true
                        };
                        db.Users.Add(user);
                        db.SaveChanges();
                        Session["User"] = user;

                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
            UserIndex userIndexModel = new UserIndex();

            userIndexModel.signUp = model;
            ViewBag.activeTab     = "signup";
            return(View("Index", userIndexModel));
        }
Beispiel #11
0
        public async Task <IActionResult> SignUp(UserSignUpVM userSignUpVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(userSignUpVM));
            }

            var result = await userService.TryRegisterAsync(userSignUpVM);

            if (!result.Succeeded)
            {
                ModelState.AddModelError(string.Empty, result.Errors.First().Description);
                return(View(userSignUpVM));
            }

            //return RedirectToAction(nameof(Login)); // Ändra så att man blir inloggad direkt och hamnar på overview

            UserLoginVM userLoginVM = userSignUpVM; // Använder en implicit operator i UserLoginVM klassen, motsvarar:

            /*
             *  UserLoginVM userLoginVM = new UserLoginVM
             *  {
             *      Username = userSignUpVM.Username,
             *      Password = userSignUpVM.Password
             *  }
             */
            await userService.TryLoginAsync(userLoginVM);

            TempData["Message"] = $"Registeringen lyckades. Välkommen {userSignUpVM.FirstName}!";
            HttpContext.Session.SetString("Name", userSignUpVM.FirstName);
            //cache.Set("supportUserName", userSignUpVM.Username);

            var success = await userService.TryLoginAsync(userLoginVM);

            //if (success.Succeeded)
            // create temp data
            return(Redirect("oversikt"));
        }
        public async Task <ActionResult> SignUp([Bind("Email,Password")] UserSignUpVM userVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = new ApplicationUser
                    {
                        Id       = Guid.NewGuid().ToString(),
                        Email    = userVM.Email,
                        Password = _passwordService.HashPassword(userVM.Password)
                    };
                    await _cosmosDbService.AddUserAsync(user);

                    var token = _tokenBuilder.BuildToken(user);
                    return(Ok(token));
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
            return(BadRequest("Invalid user model"));
        }
 public async Task <string> SignUp(UserSignUpVM user)
 {
     return(await AuthAction(_signUpEndpoint, user));
 }
Beispiel #14
0
 public async Task <IdentityResult> TryRegisterAsync(UserSignUpVM userSignUpVM)
 {
     return(await userManager.CreateAsync(new MyIdentityUser { UserName = userSignUpVM.Username }, userSignUpVM.Password));
 }