Пример #1
0
        public LoginResult AttemptLogin(string emailAddress, string password)
        {
            try
            {
                if (!AccountExists(emailAddress))
                {
                    return(LoginResult.Failure("Email Address not found"));
                }

                // get UserAccount from database using the EmailAdress (to get salt & hash)
                var userAccountRepo = new UserAccountRepository();
                var userAccount     = userAccountRepo.GetUserAccountByEmailAddress(emailAddress);

                // validate password against salt & hash
                if (!PasswordManager.ValidatePassword(password, userAccount.Salt, userAccount.Hash))
                {
                    return(LoginResult.Failure("Wrong password"));
                }

                return(LoginResult.Success(userAccount));
            }
            catch (Exception exception)
            {
                return(LoginResult.Error(exception));
            }
        }
Пример #2
0
        public async Task <IActionResult> CreateOrganisationInvite(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "OrganisationInvite/CreateOrganisationInvite")] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function(CreateOrganisationInvite) processed a request.");

            try
            {
                var accessTokenResult = _tokenProvider.ValidateToken(req);
                if (accessTokenResult.Status != AccessTokenStatus.Valid)
                {
                    return(new UnauthorizedResult());
                }

                Guid userAccountId  = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "UserAccount").Value);
                Guid organisationId = new Guid(accessTokenResult.Principal.Claims.First(c => c.Type == "Organisation").Value);

                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                var    organisationInviteCreateModel = JsonConvert.DeserializeObject <OrganisationInviteCreateModel>(requestBody);

                // Make sure the user being invited is in the database/actually signed up
                var userAccountRepository = new UserAccountRepository();
                var invitee = userAccountRepository.GetUserAccountByEmailAddress(organisationInviteCreateModel.InviteeEmailAddress);

                if (invitee == null)
                {
                    return(new BadRequestObjectResult("User does not exist"));
                }

                var organisationInvite = new OrganisationInvite()
                {
                    OrganisationId = organisationId,
                    InvitedById    = userAccountId,
                    InviteeId      = invitee.UserAccountId,
                    InviteUserType = organisationInviteCreateModel.InviteUserType
                };

                var organisationInviteRepo = new OrganisationInviteRepository();
                var newId = organisationInviteRepo.CreateOrganisationInvite(organisationInvite);

                return(new OkObjectResult("Invited"));
            }
            catch (Exception exception)
            {
                return(new BadRequestObjectResult(exception.Message));
            }
        }