Пример #1
0
 public AccountDTO AddAccountToCompany(int currentAccountId, AccountCreateDTO newaccount)
 {
     try {
         var current        = _accountRepository.GetAccount(currentAccountId);
         var currentcompany = current.Company;
         if (currentcompany != null)
         {
             if ((current.Type == eAccountType.Owner || current.Type == eAccountType.Administrator) && IsVatInDatabase(currentcompany.VAT) && !IsEmailInDatabase(newaccount.Email))
             {
                 Account account = Mapper.Map <AccountCreateDTO, Account>(newaccount);
                 Company company = currentcompany;
                 string  salt    = PasswordValidationService.GetInstance().GenerateSalt();
                 account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(newaccount.Password, salt);
                 account.Salt     = salt;
                 account.Company  = _companyRepository.AddNewCompany(company);
                 account          = _accountRepository.AddNewAccount(account);
                 var accountviewmodel = Mapper.Map <Account, AccountDTO>(account);
                 return(Mapper.Map <Account, AccountDTO>(current));
             }
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
     return(null);
 }
Пример #2
0
        public async Task <ActionResult> Register(AccountCreateDTO model)
        {
            if (ModelState.IsValid)
            {
                if (model.Email.Equals(model.ConfirmEmail, StringComparison.CurrentCultureIgnoreCase))
                {
                    var account = await _accountservice.CreateAccount(model);

                    if (account != null)
                    {
                        CurrentUser.InstantiateCurrentUser(account);
                        return(RedirectToAction(nameof(HomeController.Index), "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError(model.Email, "Bruger blev ikke gemt");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError(model.Email, "Email matcher ikke");
                    return(View(model));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #3
0
        public async Task <ActionResult> Register(AccountCreateDTO accountCreateDto)
        {
            try
            {
                await AccountFacade.RegisterAccount(accountCreateDto);

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

                var authTicket = new FormsAuthenticationTicket(1, accountCreateDto.Email, 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", "Home"));
            }
            catch (ArgumentException)
            {
                ModelState.AddModelError("Email Address", "Account with that email address already exists!");
                return(View());
            }
            catch (DbEntityValidationException)
            {
                return(View());
            }
            catch (SqlException)
            {
                return(View());
            }
        }
Пример #4
0
        public async Task <Guid> RegisterAccountAsync(AccountCreateDTO accountDto)
        {
            var account = Mapper.Map <Account>(accountDto);

            if (await GetIfAccountExistsAsync(account.Email))
            {
                throw new ArgumentException();
            }

            Repository.Create(account);
            return(account.Id);
        }
Пример #5
0
        public ActionResult <AccountCreateDTO> CreateAccount(AccountCreateDTO accountDTO)
        {
            var accountModel = _mapper.Map <Account>(accountDTO);

            _repository.CreateAccount(accountModel);
            _repository.SaveChanges();

            var accountReadDTO = _mapper.Map <AccountReadDTO>(accountModel);

            return(CreatedAtRoute(
                       nameof(GetAccountById),
                       new { accountReadDTO.Id },
                       accountReadDTO
                       ));
        }
Пример #6
0
 public IHttpActionResult AddAccountToCompany(int currentAccountId, [FromBody] AccountCreateDTO newaccount)
 {
     if (ModelState.IsValid)
     {
         var acc = _accountService.AddAccountToCompany(currentAccountId, newaccount);
         if (acc != null)
         {
             return(Ok(acc));
         }
         else
         {
             return(BadRequest("Bruger blev ikke lavet"));
         }
     }
     return(BadRequest(ModelState));
 }
Пример #7
0
 public IHttpActionResult CreateNewAccount([FromBody] AccountCreateDTO newaccount)
 {
     if (ModelState.IsValid)
     {
         var acc = _accountService.CreateNewAccount(newaccount);
         if (acc != null)
         {
             return(Ok(acc));
         }
         else
         {
             return(BadRequest("Bruger blev ikke lavet. Enten fejl af input eller server fejl"));
         }
     }
     return(BadRequest(ModelState));
 }
Пример #8
0
        public async Task <Guid> RegisterAccount(AccountCreateDTO accountCreateDto)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                try
                {
                    var id = await accountService.RegisterAccountAsync(accountCreateDto);

                    await uow.Commit();

                    return(id);
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
        }
Пример #9
0
        public AccountDTO CreateNewAccount(AccountCreateDTO newaccount)
        {
            try {
                if (newaccount.Email.IsValidEmail() && !IsEmailInDatabase(newaccount.Email))
                {
                    Account account = Mapper.Map <AccountCreateDTO, Account>(newaccount);

                    string salt = PasswordValidationService.GetInstance().GenerateSalt();
                    account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(newaccount.Password, salt);
                    account.Salt     = salt;
                    account          = _accountRepository.AddNewAccount(account);
                    var accountviewmodel = Mapper.Map <Account, AccountDTO>(account);
                    return(accountviewmodel);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(null);
        }
        public async Task <IActionResult> CreateAccount([FromBody] AccountCreateDTO account)
        {
            // validate data
            if (!account.Email.IsEmail() ||
                (!string.IsNullOrWhiteSpace(account.AvatarPath) && !account.AvatarPath.IsUrl()))
            {
                return(ValidationProblem());
            }

            if ((await _context.Accounts.FirstOrDefaultAsync(x => x.Email == account.Email))
                != null)
            {
                return(BadRequest(new
                {
                    error = "Already exists a account with this email"
                }));
            }

            var _account = _mapper.Map <Account>(account);

            _account.CreatedAt  = DateTime.UtcNow;
            _account.ModifiedAt = DateTime.UtcNow;
            _account.Password   = string.Empty;
            _account.Active     = false;
            // _account.Password = _passwordHasher.HashPassword(_account.Email, account.Password);
            _account.Roles = new List <AccountRole>();

            if (account.RolesId.Count == 0)
            {
                return(BadRequest(new
                {
                    error = $"The account must have least one role"
                }));
            }

            foreach (var roleId in account.RolesId)
            {
                var role = await _context.Roles.FindAsync(roleId);

                if (role == null)
                {
                    return(BadRequest(new
                    {
                        error = $"The role with id: {roleId} don't exists"
                    }));
                }
                _account.Roles.Add(new AccountRole
                {
                    Account = _account,
                    Role    = role
                });
            }

            await _context.Accounts.AddAsync(_account);

            var token = GenerateJSONWebToken(_account, expires: 1440);

            try
            {
                var url = $"https://admin.streamingcuba.com/confirm-account?token={token}";
                await _emailSender.SendEmailAsync(account.Email,
                                                  subject : "[StreamingCuba Team]",
                                                  message : $"{url}");

                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(CreateAccount), new { id = _account.Id }));
            }
            catch
            {
                return(StatusCode(501)); // Bad Gateway (Unable to send reset password link)
            }
        }
Пример #11
0
        public async Task <AccountDTO> AddAccountToCompany(int currentaccount, AccountCreateDTO model)
        {
            var user = await client.GetResponseObject <AccountCreateDTO, AccountDTO>(string.Format("{0}/add", currentaccount), eHttpMethodType.POST, model);

            return(user);
        }
Пример #12
0
        public async Task <AccountDTO> CreateAccount(AccountCreateDTO model)
        {
            var user = await client.GetResponseObject <AccountCreateDTO, AccountDTO>("create", eHttpMethodType.POST, model);

            return(user);
        }