public IActionResult EditAccountRequest(AccountRequestDto accountRequestDto)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var request = _workoutRepository.GetAccountRequest(accountRequestDto.id);

            if (request == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            request.Email    = accountRequestDto.Email;
            request.Complete = accountRequestDto.Complete;
            _workoutRepository.ModifyAccountRequest(request);

            if (!_workoutRepository.Save())
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("ViewAccountRequests", "Account"));
        }
        public IActionResult ViewAccountRequests()
        {
            var accountRequests = _workoutRepository.GetAccountRequests();
            var model           = new AccountRequestDto();

            model.AccountRequests = accountRequests;

            return(View(model));
        }
        public IActionResult ViewAccountRequest(int id)
        {
            var accountRequest = _workoutRepository.GetAccountRequest(id);
            var model          = new AccountRequestDto();

            model.Email    = accountRequest.Email;
            model.Complete = accountRequest.Complete;

            return(View(model));
        }
 public ActionResult CreateAccount(AccountModel AccountModel)
 {
     using (HttpClient client = new HttpClient())
     {
         client.DefaultRequestHeaders.Add("Authorization", Session["TokenKey"].ToString());
         AccountRequestDto request = AccountModel.GetDto();
         var jsonRequestString     = JsonConvert.SerializeObject(request);
         var stringContent         = new StringContent(jsonRequestString, UnicodeEncoding.UTF8, "application/json");
         var response = client.PostAsync(endPoints.CreateAccount, stringContent).Result;
     }
     ViewBag.message = "Account has been registered!";
     return(View("CreateAccount"));
 }
        public IActionResult UpdateAccountRequest(AccountRequestDto accountRequestDto)
        {
            var accountRequest = _pollDataRepository.GetAccountRequest(accountRequestDto.Id);

            if (accountRequest != null)
            {
                accountRequest.Email    = accountRequestDto.Email;
                accountRequest.UserName = accountRequestDto.UserName;
                accountRequest.Complete = accountRequestDto.Complete;

                _pollDataRepository.UpdateAccountRequest(accountRequest);
            }

            return(RedirectToAction(nameof(ViewAccountRequests)));
        }
        public IActionResult EditAccountRequest(int id)
        {
            var request = _workoutRepository.GetAccountRequest(id);

            if (request == null)
            {
                return(RedirectToAction("ViewAccountRequests", "Account"));
            }

            var model = new AccountRequestDto();

            model.id       = request.Id;
            model.Email    = request.Email;
            model.Complete = request.Complete;

            return(View(model));
        }
        public IActionResult CreateAccountRequest(AccountRequestDto accountRequestDto)
        {
            var accountRequest = new AccountRequest();

            accountRequest.Email = accountRequestDto.Email;

            if (accountRequestDto.UserName != "")
            {
                accountRequest.UserName = accountRequestDto.UserName;
            }

            accountRequest.Complete = false;

            _pollDataRepository.AddAccountRequest(accountRequest);

            return(RedirectToAction(nameof(SuccessfulRequest)));
        }
Example #8
0
        public int Login(AccountRequestDto dto)
        {
            var logInResponse = _authenticationService.LogIn(dto);

            if (logInResponse == null)
            {
                return(-1);
            }

            var cookieOptions = new CookieOptions
            {
                Expires = DateTime.Now.AddMinutes(15)
            };

            Response.Cookies.Append("authentication", logInResponse.CookieContent, cookieOptions);

            return(logInResponse.Id);
        }
Example #9
0
        public async Task <AccountResponseDto> AddAccount(AccountRequestDto account)
        {
            Account user = await _repository.Get(account.Email);

            if (user != null)
            {
                return(null);
            }
            Account encryptedPasswordAccount = new Account
            {
                DateOfBirth = account.DateOfBirth,
                Email       = account.Email.ToLower(),
                FirstName   = account.FirstName,
                LastName    = account.LastName,
                Password    = BCrypt.Net.BCrypt.HashPassword(account.Password),
                PhoneNumber = account.PhoneNumber
            };

            return(_mapper.Map <AccountResponseDto>(await _repository.AddAccount(encryptedPasswordAccount)));
        }
        public IActionResult CreateAccountRequest(AccountRequestDto accountRequestDto)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("CreateAccountRequest", "Account"));
            }

            var accountRequest = new AccountRequest();

            accountRequest.Email    = accountRequestDto.Email;
            accountRequest.Complete = false;

            _workoutRepository.AddAccountRequest(accountRequest);

            if (!_workoutRepository.Save())
            {
                return(RedirectToAction("CreateAccountRequest", "Account"));
            }

            return(RedirectToAction("SuccessfulAccountRequest", "Account"));
        }
Example #11
0
        public LogInResponseDto LogIn(AccountRequestDto dto)
        {
            var sha          = SHA256.Create();
            var passwordHash = sha.ComputeHash(Encoding.UTF8.GetBytes(dto.Password));
            var account      = _accountRepository.GetAccountByUsernameAndPassword(dto.Username, passwordHash);

            if (account == null)
            {
                return(null);
            }

            var token         = account.Id + ":" + account.Email + ":" + Secret;
            var hashedToken   = Sha256Hash(token);
            var cookieContent = account.Id + ":" + hashedToken;

            return(new LogInResponseDto
            {
                Id = account.Id,
                CookieContent = cookieContent
            });
        }
Example #12
0
 public void Register(AccountRequestDto dto)
 {
     _accountService.AddUser(dto);
 }