Ejemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] UserToRegister userToRegister)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _mapper.Map <User> (userToRegister);

            if (await _repository.UserExists(user))
            {
                return(BadRequest("User already exists"));
            }
            user.EmailVerified = false;
            try {
                _repository.CreateUser(user, userToRegister.Password);
                var message = new Message {
                    FromName    = "CaseMan",
                    FromEmail   = "*****@*****.**",
                    ToName      = user.Name,
                    ToEmail     = user.Email,
                    Subject     = "Account Creation",
                    HtmlContent = "Your account was created successfully"
                };
                _repository.SendEmail(message);
                await _repository.SaveAllChanges();

                return(Ok());
            } catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <UserDetail> RegisterAsync(UserToRegister userToRegister)
        {
            if (userToRegister.Password != userToRegister.ConfirmPassword)
            {
                throw new Exception("Hasła nie są takie same.");
            }

            if (await _userManager.FindByNameAsync(userToRegister.UserName) != null)
            {
                throw new Exception("Username is already taken.");
            }

            var userToCreate = _mapper.Map <AppUser>(userToRegister);

            var result = await _userManager.CreateAsync(userToCreate, userToRegister.Password);

            if (userToRegister.Role.ToLower() == "admin")
            {
                await _userManager.AddToRoleAsync(userToCreate, "Admin");
            }
            else
            {
                await _userManager.AddToRoleAsync(userToCreate, "User");
            }

            if (!result.Succeeded)
            {
                throw new Exception(result.Errors.ToString());
            }

            return(_mapper.Map <UserDetail>(userToCreate));
        }
Ejemplo n.º 3
0
        public static async Task <User> Register(this IdapadDataAccess dataAccess, UserRegister userRegister)
        {
            byte[] passwordHash, passwordSalt;

            CreatePasswordHash(userRegister.Password, out passwordHash, out passwordSalt);

            var userToRegister = new  UserToRegister
            {
                FirstName    = userRegister.FirstName,
                LastName     = userRegister.LastName,
                UserName     = userRegister.UserName.ToLower(),
                EmailAddress = userRegister.EmailAddress,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt
            };

            var id = await dataAccess.ExecuteScalarAsync <int>(
                @"INSERT Appuser(FirstName, LastName, UserName, EmailAddress, PasswordHash, PasswordSalt)" +
                " output inserted.Id VALUES(@FirstName, @LastName, @UserName, @EmailAddress, @PasswordHash, @PasswordSalt)",
                userToRegister);

            var user = new User();

            user.Id           = id;
            user.FirstName    = userToRegister.FirstName;
            user.LastName     = userToRegister.LastName;
            user.UserName     = userToRegister.UserName;
            user.EmailAddress = userToRegister.EmailAddress;
            return(user);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> SignUp(UserToRegister model)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser
                {
                    UserName    = model.Name,
                    Email       = model.Email,
                    PhoneNumber = model.Phone
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Customer");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                return(Content(result.Errors.FirstOrDefault().Description));
            }
            return(View(model));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Register([FromBody] UserToRegister userToRegister)
        {
            //validate request
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!string.IsNullOrEmpty(userToRegister.Username))
            {
                userToRegister.Username = userToRegister.Username.ToLower();
            }

            if (await _repo.UserExists(userToRegister.Username))
            {
                ModelState.AddModelError("Username", "Username already exists");
                return(BadRequest(ModelState));
            }


            var userToCreate = _mapper.Map <User>(userToRegister);

            var createdUser = await _repo.Register(userToCreate, userToRegister.Password);


            return(Ok(createdUser));
        }
Ejemplo n.º 6
0
        public static async Task <User> Login(this IdapadDataAccess dataAccess, UserRegister userRegister)
        {
            var userName = userRegister.UserName.ToLower();

            UserToRegister userToRegister = await dataAccess.QueryFirstOrDefaultAsync <UserToRegister>
                                                ("select a.*,fu.FirmId, f.Name FirmName from Appuser a " +
                                                "left join FirmUsers fu On a.Id = fu.UserId  " +
                                                "left join Firm f On f.Id = fu.firmId  " +
                                                "where a.UserName = @UserName", new { userName });

            if (userToRegister == null)
            {
                return(null);
            }
            if (!VerifyPasswordHash(userRegister.Password, userToRegister.PasswordHash, userToRegister.PasswordSalt))
            {
                return(null);
            }

            var user = new User();

            user.Id           = userToRegister.Id;
            user.FirstName    = userToRegister.FirstName;
            user.LastName     = userToRegister.LastName;
            user.UserName     = userToRegister.UserName;
            user.EmailAddress = userToRegister.EmailAddress;
            user.FirmName     = userToRegister.FirmName;
            user.FirmId       = userToRegister.FirmId;
            return(user);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new user
        /// </summary>
        /// <param name="aUser">object with user details to create</param>
        /// <returns>Returned result</returns>
        public async Task <IdentityResult> CreateUser(UserToRegister aUser)
        {
            if (aUser == null)
            {
                throw new NullReferenceException("Register Model is null");
            }

            if (aUser.PassWord != aUser.ConfirmPassWord)
            {
                throw new ArgumentException("Passwords do not match");
            }

            var user = new ApplicationUser();

            user.FirstName = aUser.FirstName;
            user.LastName  = aUser.LastName;
            user.UserName  = aUser.Email;
            user.Photo     = aUser.Photo;
            user.Email     = aUser.Email;

            var result = await UserManager.CreateAsync(user, aUser.PassWord);

            if (result.Succeeded)
            {
                await UserManager.AddToRoleAsync(user, "Admin");
            }

            return(result);
        }
Ejemplo n.º 8
0
        public void UserRegistration_Register_OtherUserType_MemberCreated_PasswordSaved_ConfirmationEmailSent()
        {
            // Arrange & Act & Assert
            UserToRegister user = GetUserToRegister(isValtechUkEmail: false);

            UserRegistration_Register_MemberCreated_PasswordSaved_ConfirmationEmailSent(user);
        }
Ejemplo n.º 9
0
 private void AssertIfMemberWasCreated(UserToRegister user, IMember registeredUser, bool shouldBeApproved)
 {
     _memberService.Received(1).CreateMemberWithIdentity(user.Username, user.Email, user.Name, DefaultMemberType);
     _memberService.Received(1).SavePassword(Arg.Is <IMember>(m => m.IsApproved == shouldBeApproved), user.Password);
     _memberService.Received(1).Save(registeredUser);
     _memberService.Received(1).AssignRole(registeredUser.Id, RegularMemberGroup);
 }
Ejemplo n.º 10
0
        public void Register(UserToRegister user)
        {
            IMember registeredUser = CreateMember(user);

            SaveRegistrationConfirmation(registeredUser.Id, user.LoginType, out string token);
            SendConfirmationEmail(token, registeredUser.Email);
        }
        public UserRegisteredDto RegisterUser(UserToRegister userToRegister)
        {
            Guid   userGuid       = Guid.NewGuid();
            string hashedPassword = Security.Security.HashSHA1(userToRegister.Password + userGuid.ToString());
            string statusMessage  = "";
            bool   wasUserAdded   = false;

            bool doesUserWithGivenLoginExist = _dbContext.Users.Any(i => i.Email == userToRegister.Email);

            if (!doesUserWithGivenLoginExist)
            {
                _dbContext.Users.Add(
                    new User()
                {
                    Name     = userToRegister.Name,
                    Surname  = userToRegister.Surname,
                    Password = hashedPassword,
                    UserGuid = userGuid,
                    Email    = userToRegister.Email,
                    IsAdmin  = false,
                });
                _dbContext.SaveChanges();
                wasUserAdded = true;
            }
            else
            {
                statusMessage = "There is a user with given login or email.";
            }

            return(new UserRegisteredDto()
            {
                Success = wasUserAdded,
                Status = statusMessage
            });
        }
Ejemplo n.º 12
0
        private IMember GetRegisteredMember(UserToRegister user)
        {
            IMember registeredMember = Substitute.For <IMember>();

            registeredMember.Id    = RegisteredMemberId;
            registeredMember.Email = user.Email;

            return(registeredMember);
        }
        public async Task <IActionResult> RegisterUser([FromBody] UserToRegister model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userService.RegisterUser(model.Id, model.Name);

            return(CreatedAtRoute(Routes.GetUserById, new { id = user.Id }, _mapper.Map <User>(user)));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> SignUp([FromBody] UserToRegister aUser)
        {
            if (ModelState.IsValid)
            {
                var result = await _accountServices.CreateUser(aUser);

                return(Ok(result));
            }

            return(NotFound());
        }
Ejemplo n.º 15
0
        public static List <KeyValuePair <RegisterField, string> > CheckInputs(UserToRegister user)
        {
            var list = new List <KeyValuePair <RegisterField, string> >();

            list.Add(new KeyValuePair <RegisterField, string>(RegisterField.FirstName, user.FirstName == "" ? "Campo vacío" : ""));
            list.Add(new KeyValuePair <RegisterField, string>(RegisterField.LastName, user.LastName == "" ? "Campo vacío" : ""));
            list.Add(new KeyValuePair <RegisterField, string>(RegisterField.NickName, user.NickName == "" ? "Campo vacío" : ""));
            list.Add(new KeyValuePair <RegisterField, string>(RegisterField.Password, user.Password == "" ? "Campo vacío" : ""));

            return(list);
        }
Ejemplo n.º 16
0
 public async Task <IActionResult> RegisterAsync(UserToRegister userToRegister)
 {
     try
     {
         return(Ok(await _service.RegisterAsync(userToRegister)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 17
0
        public IActionResult Register(UserToRegister userToRegister)
        {
            userToRegister.Username = userToRegister.Username.ToLower();
            var createdBool = _authRepository.registerUser(userToRegister);

            if (!createdBool)
            {
                return(BadRequest("Ya existe Usuario"));
            }
            return(Ok());
        }
Ejemplo n.º 18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Register);

            firstNameLay = FindViewById <TextInputLayout>(Resource.Id.firstnameRegisterLay);
            lastNameLay  = FindViewById <TextInputLayout>(Resource.Id.lastnameRegisterLay);
            nicknameLay  = FindViewById <TextInputLayout>(Resource.Id.nicknameRegisterLay);
            passwordLay  = FindViewById <TextInputLayout>(Resource.Id.passwordRegisterLay);
            registerBtn  = FindViewById <Button>(Resource.Id.sendRegisterBtn);

            user = new UserToRegister();

            registerBtn.Click += async(s, e) =>
            {
                registerBtn.Enabled = false;

                user.FirstName = firstNameLay.EditText.Text;
                user.LastName  = lastNameLay.EditText.Text;
                user.NickName  = nicknameLay.EditText.Text;
                user.Password  = passwordLay.EditText.Text;
                user.Country   = "Peru";
                user.Birthday  = new DateTime(1997, 5, 12);
                user.Email     = GetRandomString();

                var validation = ViewModels.RegisterViewModel.CheckInputs(user);

                if (!validation.Any(p => p.Value != ""))
                {
                    try
                    {
                        await Services.PicSayAndPlayService.RegisterUser(user);

                        Intent i = new Intent(this, typeof(Activities.WelcomeActivity));
                        i.AddFlags(ActivityFlags.ClearTop);
                        i.SetFlags(ActivityFlags.NewTask);
                        i.PutExtra("userName", $"{user.FirstName.ToUpperInvariant()} {user.LastName.ToUpperInvariant()}");
                        StartActivity(i);
                        this.Finish();
                    }
                    catch
                    {
                        Snackbar.Make(s as Android.Views.View, "Ups! Hubo un error", Snackbar.LengthLong).Show();
                    }
                }
                else
                {
                    ShowErrors(validation);
                }

                registerBtn.Enabled = true;
            };
        }
        public async Task <ActionResult <UserDto> > Register(UserToRegister userToRegister)
        {
            //if (await UserExists(userToRegister.Username)) return BadRequest("Username is taken");
            var user = await _userManager.CreateUser(userToRegister);

            return(user);
            //return new UserDto
            //{
            //    UserName = userToRegister.Username,
            //    Token = _tokenService.CreateToken(user)
            //};
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Register(UserToRegister userToRegister)
        {
            userToRegister.Username = userToRegister.Username.ToLower();
            if (await _repo.UserExists(userToRegister.Username))
            {
                return(BadRequest("UserExists"));
            }
            var userToCreate = new User
            {
                Username = userToRegister.Username
            };
            var createdUser = await _repo.Register(userToCreate, userToRegister.Password);

            return(StatusCode(201));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Register(UserToRegister userToRegister)
        {
            userToRegister.Username = userToRegister.Username.ToLower();
            if (await _repo.UserExist(userToRegister.Username))
            {
                return(BadRequest("User already exists!"));
            }

            var userToCreate = _mapper.Map <User>(userToRegister);
            var createdUser  = await _repo.Register(userToCreate, userToRegister.Password);

            var userDetails = _mapper.Map <UserForDetailedDto>(createdUser);

            return(CreatedAtRoute("GetUser", new { controller = "Users", id = createdUser.id }, userDetails));
        }
Ejemplo n.º 22
0
        public void AccountService_Register_CanRegister_Success()
        {
            // Arrange
            IMember        existedMember = null;
            UserToRegister user          = GetUserToRegister();

            _memberService.GetByEmail(user.Email).Returns(existedMember);

            // Act
            Result registrationResult = _accountService.Register(user);

            // Assert
            Assert.IsNotNull(registrationResult, Common.ShowResponseTypeMismatchMessage(typeof(Result)));
            Assert.IsTrue(registrationResult.IsSuccess, Common.ShowNotSatisfiedExpectationMessage(true, "registrationResult.IsSuccess"));
            _userRegistration.Received(1).Register(Arg.Is(RegistrationPredicate(user)));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Register(UserToRegister userForRegisterDto)
        {
            userForRegisterDto.username = userForRegisterDto.username.ToLower();
            if (await _repo.UserExists(userForRegisterDto.username))
            {
                return(BadRequest("Username already exist"));
            }

            var UserTocreate = new User
            {
                Username = userForRegisterDto.username
            };
            var createduser = await _repo.Register(UserTocreate, userForRegisterDto.password);

            return(StatusCode(201));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Register(UserToRegister userToRegister)
        {
            // if(!ModelState.IsValid)
            //     return BadRequest(ModelState);
            userToRegister.username = userToRegister.username.ToLower();
            if (await _user.UserExists(userToRegister.username))
            {
                return(BadRequest("User Already exists"));
            }
            var usertoReg      = _mapper.Map <User>(userToRegister);
            var RegisteredUser = await _user.Register(usertoReg, userToRegister.password);

            var userDetails = _mapper.Map <UserForDetailsDto>(RegisteredUser);

            return(CreatedAtRoute("GetUser", new { Controller = "Users", id = RegisteredUser.Id }, userDetails));
        }
Ejemplo n.º 25
0
        private async Task <bool> CanRegisterUser(UserToRegister userToRegister)
        {
            var doesEmailExists = await userRepository.DoesEmailAlreadyExists(userToRegister.Email);

            if (doesEmailExists)
            {
                throw new EmailAlreadyExistsException();
            }
            var doesLoginExists = await userRepository.DoesLoginAlreadyExists(userToRegister.Login);

            if (doesLoginExists)
            {
                throw new LoginAlreadyExistsException();
            }
            return(true);
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Register(UserToRegister userToRegis)
        {
            // validate request

            userToRegis.Username = userToRegis.Username.ToLower();
            if (await repo.UserExists(userToRegis.Username))
            {
                return(BadRequest("The user alredy exists"));
            }

            var userToCreate = mapper.Map <User>(userToRegis);
            var createdUser  = await repo.Register(userToCreate, userToRegis.Password);

            var userToReturn = mapper.Map <UserfForDetailedDto>(createdUser);

            return(CreatedAtRoute("GetUser", new { controller = "Users", id = createdUser.Id }, userToReturn));
        }
        public async Task<IActionResult> Register([FromBody] UserToRegister userToRegister)   
            //przeszedl walidacej
        {
            userToRegister.Username = userToRegister.Username.ToLower(); 
            if (await _authService.UserExist(userToRegister.Username))
                return BadRequest("Username alredy exist");

            var userToCreate = new User
            {
                Username = userToRegister.Username
            };

            var createdUser = _authService.Register(userToCreate, userToRegister.Password);    

          
            return StatusCode(201);
        }
Ejemplo n.º 28
0
        public async Task <UserDto> CreateUser(UserToRegister userToRegister)
        {
            using var hmac = new HMACSHA512();
            var user = new AppUser
            {
                UserName     = userToRegister.Username.ToLower(),
                PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(userToRegister.Password)),
                PasswordSalt = hmac.Key
            };
            await _userDataAccess.CreateUser(user);

            return(new UserDto
            {
                UserName = userToRegister.Username,
                Token = _tokenService.CreateToken(user)
            });
        }
        public async Task <IActionResult> Register(UserToRegister user)
        {
            var username = user.Name.ToLower();

            if (await _repo.UserExist(username))
            {
                return(BadRequest("User already exist in dabtabase!"));
            }

            User createdUser = new User {
                Name = username
            };

            var savedUser = await _repo.Register(createdUser, user.Password);

            return(StatusCode(201));
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> Create([Bind("Name,Address,Email,BookerId,Location")] UserToRegister userToRegister)
        {
            var pass = _repository.CreatePass();
            var user = Mapper.Map <User>(userToRegister);
            var mess = await _repository.CreateUser(user, pass);

            if (mess == "")
            {
                user.Password = pass;
                return(View("UserCreated", user));
            }
            else
            {
                userToRegister.ErrorMessage = String.Format("The operation failed - {0}!", mess);
                return(View("UserCreate", userToRegister));
            }
        }