/// <summary>
        /// Validate Unique Email Address
        /// </summary>
        /// <param name="emailAddress"></param>
        private async Task ValidateUniqueEmailAddress(string emailAddress)
        {
            object valueOf = GetPropertyValue(emailAddress);
            User   user    = await _accountDataService.GetUserByEmailAddress(valueOf.ToString());

            if (user != null)
            {
                AddValidationError(emailAddress, "Email Address already exists.");
            }
        }
示例#2
0
        /// <summary>
        /// Login to System
        /// </summary>
        /// <param name="AccountDataTransformation"></param>
        /// <returns></returns>
        public async Task <ResponseModel <AccountDataTransformation> > Login(AccountDataTransformation accountDataTransformation)
        {
            ResponseModel <AccountDataTransformation> returnResponse = new ResponseModel <AccountDataTransformation>();

            User    user    = new User();
            Account account = new Account();

            try
            {
                _accountManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString);

                user = await _accountManagementDataService.GetUserByEmailAddress(accountDataTransformation.EmailAddress.ToLower());

                if (user == null)
                {
                    returnResponse.ReturnStatus = false;
                    returnResponse.ReturnMessage.Add("Login incorrect.");
                    return(returnResponse);
                }

                string hashedPassword = Hasher.GenerateHash(accountDataTransformation.Password + user.PasswordSalt);

                if (user.Password != hashedPassword)
                {
                    returnResponse.ReturnStatus = false;
                    returnResponse.ReturnMessage.Add("Login incorrect.");
                    return(returnResponse);
                }

                account = await _accountManagementDataService.GetAccountInformation(user.AccountId);

                if (account == null)
                {
                    returnResponse.ReturnStatus = false;
                    returnResponse.ReturnMessage.Add("Could not find an account for user.");
                    return(returnResponse);
                }

                returnResponse.ReturnStatus = true;
            }
            catch (Exception ex)
            {
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
            }
            finally
            {
                _accountManagementDataService.CloseConnection();
            }

            accountDataTransformation.UserId       = user.UserId;
            accountDataTransformation.AccountId    = user.AccountId;
            accountDataTransformation.FirstName    = user.FirstName;
            accountDataTransformation.LastName     = user.LastName;
            accountDataTransformation.EmailAddress = user.EmailAddress;
            accountDataTransformation.CompanyName  =
                accountDataTransformation.Password = string.Empty;

            returnResponse.Entity = accountDataTransformation;

            return(returnResponse);
        }