Exemple #1
0
        public async Task <ApplicationCreateMessage> CreateWebsite(Common.Models.Account account, Website website)
        {
            Common.Models.Applications.Application application =
                _unitOfWorkApplicationSearch.Application.GetByAddress(account, website.Address);

            if (application == null)
            {
                account = _unitOfWorkAccountSearch.Account.GetWithApplications(account);

                account.CreateWebsite(website);

                _unitOfWorkApplicationSearch.Save();

                return(new ApplicationCreateMessage()
                {
                    Success = true,
                    Message = ""
                });
            }

            return(new ApplicationCreateMessage()
            {
                Success = false,
                Message = "You already have an application with this address"
            });
        }
Exemple #2
0
        public async Task <AccountMessage> Register(RegisterAccount _account)
        {
            Common.Models.Account accountUsername = _unitOfWorkAccountSearch.Account.GetByUsername(_account.Username);
            //Common.Models.Account accountEmail = await _dbContext.Account.FirstOrDefaultAsync(a => a.Username == _account.Username);

            if (accountUsername != null)
            {
                return(new AccountMessage()
                {
                    Success = false,
                    Message = "Username is already in use"
                });
            }

            Common.Models.Account acc = new Common.Models.Account()
            {
                Username = _account.Username,
                Password = Argon2.Hash(_account.Password)
            };

            _unitOfWorkAccount.Account.Add(acc);

            _unitOfWorkAccount.Save();

            return(new AccountMessage()
            {
                Success = true,
                Message = acc.GenerateJwt()
            });
        }
        public IHttpActionResult GetById(int accountId)
        {
            Rp3.Test.Common.Models.Account commonModel = null;
            using (DataService service = new DataService())
            {
                var model = service.Accounts.GetByID(accountId);

                commonModel = new Common.Models.Account()
                {
                    Email    = model.Email,
                    FullName = model.FullName
                };
            }
            return(Ok(commonModel));
        }
Exemple #4
0
        public async Task <bool> Delete(Common.Models.Account account, ApplicationRemove website)
        {
            Common.Models.Applications.Application web = _unitOfWorkApplicationSearch.Application.GetByOwnerAndTrackingCode(account, website.TrackingCode);

            if (web == null)
            {
                return(false);
            }

            _unitOfWorkApplication.Application.Remove(web);

            _unitOfWorkApplication.Save();

            return(true);
        }
Exemple #5
0
        public async Task <AuthenticationResponse> Authenticate(LoginAccount loginAccount)
        {
            Common.Models.Account account = _unitOfWorkAccountSearch.Account.GetByUsername(loginAccount.Username);

            if (account != null)
            {
                if (account.VerifyPassword(loginAccount.Password))
                {
                    return(new AuthenticationResponse()
                    {
                        Success = true,
                        Token = account.GenerateJwt()
                    });
                }
            }

            return(new AuthenticationResponse()
            {
                Success = false,
                Message = "Invalid username and/or password"
            });
        }
Exemple #6
0
        public async Task <SearchResults> Search(Common.Models.Account _account, SearchRequest searchRequest)
        {
            Common.Models.Account account = _unitOfWorkAccountSearch.Account.GetWithApplications(_account);

            return(await account.Search(searchRequest));
        }
Exemple #7
0
 public async Task <ActionResult <IList> > GetWebsites(Common.Models.Account account)
 {
     return(_unitOfWorkApplicationSearch.Application.GetWebsitesByOwner(account).Select(app => new { app.Address, app.Name, app.TrackingCode, app.Active }).ToList());
 }