Esempio n. 1
0
        //public async Task<IActionResult> Register([FromBody] RegisterAccountViews model)
        //{
        //try
        //{
        //    var result = await _accountService.Register(model);
        //    return Ok(result);
        //}
        //catch (BusinessLogicException exception)
        //{
        //    return BadRequest(exception);
        //}
        //catch (Exception exeption)
        //{
        //    _logger.LogInformation(exeption.Message);
        //    return StatusCode((int)HttpStatusCode.InternalServerError);
        //}

        public async Task <IActionResult> Register(RegisterAccountView model)
        {
            User user = new User {
                Email = model.Email, UserName = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.Action(
                    "ConfirmEmail",
                    "Account",
                    new { userId = user.Id, code = code },
                    protocol: HttpContext.Request.Scheme);
                EmailService emailService = new EmailService();
                await emailService.SendEmailAsync(model.Email, "Confirm you account",
                                                  $"Подтвердите регистрацию перейдя по ссылке: <a href = '{callbackUrl}'>link/a");

                return(Content("Для завершения регистрации проверьте электронную почту и перейдите по ссылке, указанной в письме"));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            return(Ok(model));
        }
Esempio n. 2
0
        public async Task <RegisterAccountResponseView> Register(RegisterAccountView model)
        {
            var existedPlayear = await _userManager.FindByNameAsync(model.UserName);

            if (existedPlayear != null)
            {
                throw new CustomServiceException("Player allready exist.");
            }

            var email = (!string.IsNullOrEmpty(model.Email)) ? model.Email : "";
            var user  = new Player
            {
                UserName = model.UserName,
                Balance  = 1000,
                Email    = email
            };

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

            if (!createdUser.Succeeded)
            {
                throw new CustomServiceException("The user was not registered");
            }

            string token = await _jwtProvider.GenerateJwtToken(user.Email, user);

            var result = new RegisterAccountResponseView()
            {
                AccessToken = token,
                UserName    = user.UserName
            };

            return(result);
        }
Esempio n. 3
0
        public async Task <LoginAccountResponseView> Register(RegisterAccountView model)
        {
            var user = new User
            {
                UserName = model.Email,
                Email    = model.Email,
                Year     = model.Year,
                Name     = model.Name
            };
            var player = new Player()
            {
                Name   = user.Name,
                UserId = user.Id
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                throw new CustomServiceException("Registration is not complete");
            }
            await _playerRepository.Create(player);

            var encodedJwt = await _jwtProvider.GenerateJwtToken(user);

            var response = new LoginAccountResponseView()
            {
                Token = encodedJwt
            };

            return(response);
        }
Esempio n. 4
0
        public async Task <GenericResponseView <LoginAccountResponseView> > Register([FromBody] RegisterAccountView model)
        {
            var response = new GenericResponseView <LoginAccountResponseView>();

            response.Model = await _accountService.Register(model);

            return(response);
        }
Esempio n. 5
0
        public async Task <User> Register(RegisterAccountView model)
        {
            var user = new User
            {
                UserName  = model.Email,
                Email     = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Role      = "ures"
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                var errors = result.Errors.ToString();
                throw new BusinessLogicException(errors);
            }
            await _signInManager.SignInAsync(user, false);

            return(user);
        }
Esempio n. 6
0
        public async Task <RegistrationAccountResponseView> Register(RegisterAccountView model)
        {
            var account = new User
            {
                UserName = model.Name,
            };
            var result = await _userManager.CreateAsync(account, model.Password);

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

            var token    = _jwtTokentHelper.GenerateJwtToken(account);
            var response = new RegistrationAccountResponseView()
            {
                UserId = account.Id,
                Token  = token
            };

            return(response);
        }
Esempio n. 7
0
        public async Task <LoginAccountResponseView> Register(RegisterAccountView model)
        {
            var user = new User
            {
                UserName = model.Email,
                Email    = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                throw new CustomServiceException("Invalid user");
            }


            var token    = _jwtTokentHelper.GenerateJwtToken(model.Email, user);
            var response = new LoginAccountResponseView()
            {
                Token = token
            };

            return(response);
        }
Esempio n. 8
0
        /// <summary>
        /// Renders the view where legal-aged and alive residents are displayed
        /// for the selection of the account to be registered
        /// </summary>
        public void GetRegisterAccount()
        {
            ViewContext.Dispose();

            RegisterAccountView view = new RegisterAccountView();

            var residents = dbEnt.Resident.Residents();
            // filter resilts
            // legal age and not deceased
            DateTime legalAge = new DateTime(DateTime.Now.Year - 18, DateTime.Now.Month, DateTime.Now.Day);

            residents = residents.Where(m => m.Status == SystemConstants.RESIDENT_STATUS_ALIVE && m.Birthdate <= legalAge).ToList();
            // not registered already
            List <int> existingResidentIds = dbEnt.Account.Accounts().Select(m => m.ResidentId).ToList();

            // the residents must NOT CONTAIN any id in the existingResidentIds
            residents = residents.Where(m => !existingResidentIds.Contains(m.ResidentId) && m.ResidentId != UserSession.User.ResidentId).ToList();

            view.Residents = residents;
            view.PopulateDataList();
            ViewContext.ActiveForm = view;
            ViewContext.ActiveForm.ShowDialog();
        }
Esempio n. 9
0
        public async Task <IActionResult> Register([FromBody] RegisterAccountView model)
        {
            var response = await _accountService.Register(model);

            return(Ok(response));
        }
Esempio n. 10
0
 public async Task <IActionResult> Register([FromBody] RegisterAccountView model)
 {
     return(await Execute(() => _accountService.Register(model)));
 }