Exemple #1
0
 public HttpResponseMessage SignUp([FromBody] SignUpDto signUpDto)
 {
     return(Request.ExecuteProtectedAndWrapResult <SignUpDto, AccountModel>(
                dto => AccountService.SignUp(dto),
                ModelState, signUpDto
                ));
 }
Exemple #2
0
        public async Task <UserDto> SignUpPlayer(SignUpDto credentials)
        {
            var user = await _userRepository
                       .Get(u => u.Email == credentials.Email);

            if (user != null)
            {
                throw new InvalidOperationException();
            }

            var encryptedPassword = _authService.CreatePasswordHash(credentials.Password);

            user = new User
            {
                Name         = credentials.Name,
                Email        = credentials.Email,
                PasswordHash = encryptedPassword.PasswordHash,
                PasswordSalt = encryptedPassword.PasswordSalt
            };

            _userRepository.Add(user);
            await _unitOfWork.CompleteAsync();

            var mappedUser = _mapper.Map <User, UserDto>(user);

            //mappedUser.Token = _authService.GenerateToken(user.Id);

            return(mappedUser);
        }
Exemple #3
0
        public async Task <SignedInDto> SignUp(SignUpDto signUp, params UserRole[] roles)
        {
            if (signUp == null)
            {
                throw new ArgumentException(nameof(signUp));
            }
            if (roles.Length == 0)
            {
                throw new AppException("At least one role required");
            }

            var user = _mapper.Map <AppIdentityUser>(signUp);

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

            if (!result.Succeeded)
            {
                throw new AppException(result.Errors.Select(_ => _.Description).FirstOrDefault());
            }

            await _userManager.AddToRolesAsync(user, roles.Select(_ => _.ToString()));

            await _principalService.Impersonate(user);

            return(await GetToken(user));
        }
        public ActionResult SignUp(string id)
        {
            // fetch user by id. that no, name and email will go in agreement
            var       user      = accountRepository.GetUserByID(id);
            SignUpDto signUpDto = new SignUpDto();

            if (user != null)
            {
                signUpDto.FirstName  = user.FirstName;
                signUpDto.LastName   = user.LastName;
                signUpDto.Email      = user.Email;
                signUpDto.Phone      = user.Phone;
                signUpDto.CallerName = user.CallerName;
                if (!string.IsNullOrEmpty(Convert.ToString(user.OTP)) || user.OTP != 0)
                {
                    if (user.ActivationDate != null || !string.IsNullOrEmpty(Convert.ToString(user.ActivationDate)))
                    {
                        return(RedirectToAction("LogIn"));
                    }
                }
                else
                {
                    return(RedirectToAction("VerifyOTP", new { id = id }));
                }
            }
            ModelState.AddModelError("error", "Invalid user");
            return(View(signUpDto));
        }
        public async Task <IActionResult> SignUp(SignUpDto signupDto)
        {
            try
            {
                if (signupDto == null)
                {
                    return(NotFound());                   //404
                }
                var user = new User
                {
                    Email    = signupDto.Email,
                    MobileNo = signupDto.MobileNo,
                    Name     = signupDto.Name
                };
                var isRegistered = await _authService.Register(user, signupDto.Password);

                if (isRegistered)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (System.Exception)
            {
                return(BadRequest());
            }
        }
Exemple #6
0
        public async Task <ActionResult> SignUp(SignUpDto signUpDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = _pool.GetUser(signUpDto.Username);

            if (user.Status != null)
            {
                return(BadRequest("User already exists"));
            }

            user.Attributes.Add(CognitoAttribute.Name.AttributeName, signUpDto.Name);
            user.Attributes.Add(CognitoAttribute.Email.AttributeName, signUpDto.Email);

            var createdUser = await _userManager.CreateAsync(user, signUpDto.Password);

            if (createdUser.Succeeded)
            {
                await _signInManager.SignInAsync(user, false);

                return(Ok());
            }


            return(BadRequest());
        }
Exemple #7
0
        public async Task <ActionResult> SignUp([FromBody] SignUpDto dto)
        {
            var passwordSalt = _securePasswordSaltGenerator.GenerateSecureRandomString();

            var newPasswordCredential = new PasswordCredential()
            {
                HashedPassword = _passwordHasher.HashPassword(dto.Password, passwordSalt),
                PasswordSalt   = passwordSalt
            };

            var newUser = new User()
            {
                Username           = dto.Username,
                PasswordCredential = newPasswordCredential,
                Email = new UserEmail()
                {
                    EmailAddress = dto.Email,
                    IsVerified   = false
                },
                BanLiftedDate = DateTime.MinValue
            };

            await _appDbContext.Users.AddAsync(newUser);

            await _appDbContext.SaveChangesAsync();

            await _usersController.SendEmailVerificationMessage(newUser.Id.ToString());

            return(Ok());
        }
        public async Task <PwUser> CreateUserAsync(SignUpDto signUpDto)
        {
            await CheckUserRegistred(signUpDto);

            var passwordSalt = _encryptionService.CreateSalt();
            int startBalance;

            try
            {
                startBalance = int.Parse(_configuration.GetSection("User:StartBalance").Value);
            }
            catch (Exception)
            {
                throw new PWException(CanNotGetStartBalanceMessage);
            }

            var user = new PwUser()
            {
                UserName     = signUpDto.UserName,
                Salt         = passwordSalt,
                Email        = signUpDto.Email,
                PasswordHash = _encryptionService.EncryptPassword(signUpDto.Password, passwordSalt),
                Balance      = startBalance
            };

            await _userRepository.AddAsync(user);

            return(user);
        }
Exemple #9
0
        public async Task <IActionResult> SignUp(SignUpDto data)
        {
            var user = new AppUser
            {
                UserName    = data.UserName,
                Email       = data.Email,
                PhoneNumber = data.PhoneNumber
            };
            var result = await userManager.CreateAsync(user, data.Password);

            foreach (var role in data.Roles)
            {
                await userManager.AddToRoleAsync(user, role);
            }


            if (result.Succeeded)
            {
                await signInManager.SignInAsync(user, false);

                var token = GenerateJwtToken(user, data.Roles);
                return(Ok(new { Token = token }));
            }

            return(BadRequest(result.Errors.Select(e => e.Description)));
        }
Exemple #10
0
        public async Task <IActionResult> SignUp(SignUpDto model)
        {
            if (ModelState.IsValid)
            {
                AppUser user = new AppUser()
                {
                    UserName = model.Username,
                    Email    = model.Email,
                    Name     = model.Name,
                    SurName  = model.Surname,
                    Age      = model.Age
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var addRoleResult = await _userManager.AddToRoleAsync(user, "Member");

                    if (addRoleResult.Succeeded)
                    {
                        return(RedirectToAction("SignIn"));
                    }
                    XetaElaveEt(addRoleResult.Errors);
                }

                XetaElaveEt(result.Errors);
            }

            return(View(model));
        }
Exemple #11
0
        public async Task <AccountModel> SignUp(SignUpDto signUpForm)
        {
            return(await base.Execute <AccountModel>(async() =>
            {
                using (UnitOfWork db = new UnitOfWork())
                {
                    IRepo <AccountEntity> accountRepo = db.GetRepo <AccountEntity>();

                    if (await accountRepo.FirstOrDefault(acc => acc.login == signUpForm.Login) != null)
                    {
                        throw new LoginDuplicationException();
                    }

                    PublicKeyModel publicKeyModel = signUpForm.PublicKey.ToModel <PublicKeyModel>();
                    string password = null;

                    try
                    {
                        if (signUpForm.PublicKey == null)
                        {
                            throw new InvalidKeyException();
                        }

                        AsymmetricAlgorithm algorithm = KeyService.GetKeyPair(publicKeyModel);
                        password = EncryptionService.Decrypt(signUpForm.PasswordEncrypted, algorithm);
                    }
                    catch (KeyNotFoundException) { throw new InvalidKeyException(); }
                    catch (FormatException) { throw new PostValidationException("Password format was not match Base64"); }
                    catch (CryptographicException) { throw new WrongEncryptionException("Password"); }

                    if (!PasswordPattern.IsMatch(password))
                    {
                        throw new InvalidPasswordException();
                    }

                    KeyService.DestroyKeyPair(publicKeyModel);

                    AccountEntity accountEntity = new AccountEntity()
                    {
                        login = signUpForm.Login,
                        password = HashingService.GetHashHex(password),
                        first_name = signUpForm.FirstName,
                        last_name = signUpForm.LastName
                    };

                    string authorizedRoleName = DefaultRoles.AUTHORIZED.ToName();
                    accountEntity.Roles.Add(
                        await db.GetRepo <RoleEntity>().FirstOrDefault(
                            role => role.is_default && role.name == authorizedRoleName
                            )
                        );

                    AccountEntity inserted = await accountRepo.Create(accountEntity);
                    await db.Save();

                    return inserted.ToModel <AccountModel>();
                }
            }));
        }
Exemple #12
0
        public async Task <int> SignUp(SignUpDto model)
        {
            model.Password = model.IsExternalAuth ? string.Empty : model.Password.GetSha1Hash();
            var thirdPartyAuthType = model.ThirdPartyAuthType.HasValue ? ((int)model.ThirdPartyAuthType).ToString() : "null";

            return(await ExecuteScalarAsync <int>(
                       $@"insert into users (user_name,password,first_name,last_name,email_address,is_external_auth,is_active,is_pwd_reset_required,tenant_id, activation_token,third_party_authenticator_id) VALUES (@Email,@Password, @FirstName,@LastName,@Email,@IsExternalAuth, false, false, {GET_TENANT_QUERY}, @ActivationToken, {thirdPartyAuthType}) RETURNING id",
                       model));
        }
Exemple #13
0
 public Task <SignUpResultDto> SignUp(
     SignUpDto userInfo,
     Toast toast = default(Toast))
 {
     return(httpClientService.Post <SignUpDto, SignUpResultDto>(
                "api/user/SignUp",
                userInfo,
                toast));
 }
        public async Task <IActionResult> SignUP([FromBody] SignUpDto signUpDto)
        {
            var user       = mapper.Map <User>(signUpDto);
            var loginCreds = mapper.Map <LoginCredentials>(signUpDto);

            var newUser = await authenticationProcessor.SignUpAsync(user, loginCreds);

            return(new CreatedResult($"{newUser.Id}", newUser));
        }
Exemple #15
0
 public Task <SignUpResultDto> SignUp([FromBody] SignUpDto userInfo)
 {
     return(accountService.SignUp(userInfo, p => Url.Action(
                                      "ConfirmEmail",
                                      "User",
                                      p,
                                      Request.Scheme
                                      )));
 }
        private static SignUpDto CreateDto(SignUpViewModel model)
        {
            var signUpDto = new SignUpDto(
                model.Username,
                model.Password,
                model.PasswordConfirmation,
                model.Email);

            return(signUpDto);
        }
Exemple #17
0
 private void GivenSignUpDto(string name, string email, string password, IReadOnlyCollection <TelephoneDto> telephones)
 {
     _signUpDto = new SignUpDto
     {
         Name       = name,
         Email      = email,
         Password   = password,
         Telephones = telephones
     };
 }
        public async Task <OperationResult <SignUpDto> > SignUp(SignUpDto signUpDto)
        {
            OperationResult <SignUpDto> operation = new OperationResult <SignUpDto>();

            try
            {
                using (var transaction = Context.Database.BeginTransaction())
                {
                    try
                    {
                        IdenServUser SetUser = new IdenServUser()
                        {
                            UserName           = signUpDto.UserName,
                            Email              = signUpDto.UserName,
                            NormalizedUserName = signUpDto.FirstName + " " + signUpDto.LastName
                        };

                        var result = await UserManager.CreateAsync(SetUser, signUpDto.Password);


                        if (result == IdentityResult.Success)
                        {
                            operation.Result = signUpDto;
                            operation.OperationResultType    = OperationResultTypes.Success;
                            operation.OperationResultMessage = "Success CreateAsync execution :" + nameof(SignUp);
                            transaction.Commit();
                            return(operation);
                        }

                        operation.OperationResultType    = OperationResultTypes.Failed;
                        operation.OperationResultMessage = "Faild DuplicateUserName CreateAsync execution :" + nameof(SignUp);
                        transaction.Rollback();

                        return(operation);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        operation.OperationResultType    = OperationResultTypes.Exeption;
                        operation.OperationResultMessage = "Exeption execution :" + nameof(SignUp);
                        operation.Exception = ex;

                        return(operation);
                    }
                }
            }
            catch (Exception ex)
            {
                operation.OperationResultType    = OperationResultTypes.Exeption;
                operation.OperationResultMessage = "Exeption execution :" + nameof(SignUp);
                operation.Exception = ex;
            }
            return(operation);
        }
        public IActionResult SignUp([FromBody] SignUpDto user)
        {
            var token = _usersService.Create(user);

            if (token != null)
            {
                return(Ok(token));
            }

            return(BadRequest());
        }
Exemple #20
0
        public async Task <IActionResult> SignUp([FromBody] SignUpDto data)
        {
            try {
                var user = await _userService.SignUp(data);

                return(Json(await CreateToken(user)));
            }
            catch (ValidationException ex) {
                return(BadRequest(ex.Message));
            }
        }
        public RegisterCommand(SignUpDto dto)
        {
            Dto = dto;

            var validator = new Validator();
            var result    = validator.Validate(this);

            if (!result.IsValid)
            {
                throw new ValidationException(result.Errors);
            }
        }
        public async Task <IActionResult> SignUp([FromBody] SignUpDto signUpDto)
        {
            var result = await _userService.SignUp(new User
                                                   { UserName = signUpDto.Username, PasswordHash = signUpDto.Password });

            if (result.Succeeded)
            {
                return(Ok());
            }

            return(BadRequest());
        }
        public IActionResult SaveUser([FromBody] SignUpDto signUpDto)
        {
            User user = new User();

            user.Username = signUpDto.Username;
            user.Password = signUpDto.Password;

            _IUnitOfWork.UserRepository.Insert(user);
            _IUnitOfWork.Complete();

            return(new JsonResult("ok"));
        }
Exemple #24
0
        public async Task <IActionResult> Register(SignUpDto signUpDto)
        {
            var user = new User
            {
                Email    = signUpDto.Email,
                UserName = signUpDto.UserName
            };

            await _authService.Register(user, signUpDto.Password);

            return(Ok()); //change for Created (201 code)
        }
Exemple #25
0
        public async Task <ActionResult <Result <string> > > SignUpAsync([FromBody] SignUpDto item)
        {
            try
            {
                var res = await _service.SignUpAsync(item);

                return(StatusCode(201, res));
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
        public UserDto SignUp(SignUpDto signUpDto)
        {
            //todo: call database insert records

            return(new UserDto()
            {
                Email = signUpDto.Email,
                FullName = signUpDto.FullName,
                ProfilePicUrl = string.Empty,
                PhoneNumber = signUpDto.PhoneNumber,
                UserName = signUpDto.UserName
            });
        }
Exemple #27
0
        public static User ToUser(this SignUpDto model)
        {
            var toReturn = new User()
            {
                Email        = model.Email,
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                PasswordHash = model.Password,
                UserName     = model.Email
            };

            return(toReturn);
        }
Exemple #28
0
        public IActionResult Create([FromBody] SignUpDto signUpDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Customer customer = new Customer
                {
                    OrganizationName = signUpDto.OrganizationName
                };
                notification = customer.validateForSave();

                if (notification.hasErrors())
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, notification.errorMessage()));
                }

                _customerRepository.Create(customer);

                User user = new User
                {
                    Username = signUpDto.Username,
                    Password = signUpDto.Password,
                    RoleId   = (long)Role.Owner,
                    Customer = customer
                };
                _userRepository.Create(user);

                Project project = new Project
                {
                    ProjectName = signUpDto.ProjectName,
                    Customer    = customer,
                    Budget      = signUpDto.Budget,
                    CurrencyId  = (long)Currency.EUR
                };
                _projectRepository.Create(project);

                _unitOfWork.Commit(uowStatus);
                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto("Customer, user and project created!")));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto("Internal Server Error")));
            }
        }
Exemple #29
0
        public IActionResult Create([FromBody] SignUpDto signUpDto)
        {
            Notification notification = new Notification();
            bool         uowStatus    = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();

                Student student = _studentAssembler.FromSignUpDtoToStudent(signUpDto);
                notification = student.validateForSave();

                if (notification.hasErrors())
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, notification.ToString()));
                }

                _studentRepository.Create(student);

                Project project = _projectAssembler.FromSignUpDtoToProject(signUpDto);

                /*Special Case Patternn*/
                var projectGet = ExistProject(project);
                if (!string.IsNullOrEmpty(projectGet.ProjectName))
                {
                    project.Student = student;
                    /*Null Object Pattern*/
                    var calc_NumberDaysProject = new calc_NumberDaysProject();
                    project.NumberDaysProject = calc_NumberDaysProject.getNumberDaysProject(project.NumberDaysProject).GetNumberProjectDays();
                    /*-----------------------------*/

                    _projectRepository.Create(project);
                }

                _unitOfWork.Commit(uowStatus);

                var message = "Customer, user and project created!";
                KipubitRabbitMQ.SendMessage(message);

                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto(message)));
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                var message = "Internal Server Error";
                KipubitRabbitMQ.SendMessage(message);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto(message)));
            }
        }
Exemple #30
0
        public IActionResult SignUp([FromBody] SignUpDto signUpDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }
            var registrationResult = AuthService.SignUp(signUpDto);

            if (registrationResult.Result == SMResult.Success)
            {
                return(Json(ConfigureUserToken(registrationResult.Entity)));
            }
            return(Json("Failed"));
        }