/// <summary>
        /// Performs Applicant registration
        /// </summary>
        /// <param name="userApplicantCreateDto">Applicant registration details</param>
        /// <returns>Registered Applicant account ID</returns>
        public async Task <Guid> RegisterApplicant(UserApplicantCreateDto userApplicantCreateDto)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var id = await userService.RegisterUserAsync(userApplicantCreateDto);

                await uow.Commit();

                return(id);
            }
        }
Exemplo n.º 2
0
        public async Task <Guid> RegisterUserAsync(UserApplicantCreateDto userDto)
        {
            var applicant = Mapper.Map <Applicant>(userDto);

            if (await GetIfUserExistsAsync(applicant.Username))
            {
                throw new ArgumentException();
            }

            var password = CreateHash(userDto.Password);

            applicant.PasswordHash = password.Item1;
            applicant.PasswordSalt = password.Item2;

            applicantRepository.Create(applicant);

            return(applicant.Id);
        }
        public async Task <ActionResult> RegisterApplicant(UserApplicantCreateDto userApplicantCreateDto)
        {
            try
            {
                await ApplicantFacade.RegisterApplicant(userApplicantCreateDto);

                //FormsAuthentication.SetAuthCookie(userCreateDto.Username, false);

                var authTicket = new FormsAuthenticationTicket(1, userApplicantCreateDto.Username, DateTime.Now,
                                                               DateTime.Now.AddMinutes(30), false, "");
                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                HttpContext.Response.Cookies.Add(authCookie);

                return(RedirectToAction("Index", "Applicant"));
            }
            catch (ArgumentException)
            {
                ModelState.AddModelError("Username", "Account with that username already exists!");
                return(View());
            }
        }