示例#1
0
        public bool ForgotPassword(string email)
        {
            ValidationService.ValidEmail(email);
            User _user = repository.GetByEmail(email);

            if (_user == null)
            {
                throw new ApiException("Email not found", HttpStatusCode.NotFound);
            }

            _user.Code = UtilsService.GenerateCode(8);

            repository.Update(_user);

            emailSender.SendEmailAsync(new EmailViewModel(new string[] { _user.Email }, "Change Password - AltaCafe", "FORGOT-PASSWORD"), new string[] { _user.Name, _user.Code });

            return(true);
        }
示例#2
0
        public bool ChangePassword(UserRequestChangePasswordViewModel user)
        {
            ValidationService.ValidEmail(user.Email);
            ValidationService.ValidPassword(user.Password, user.PasswordConfirm);

            User _user = repository.GetByEmailAndCode(user.Email, user.Code);

            if (_user == null)
            {
                throw new ApiException("Email/Code not found", HttpStatusCode.NotFound);
            }

            _user.Code     = string.Empty;
            _user.Password = UtilsService.EncryptPassword(user.Password);
            repository.Update(_user);

            emailSender.SendEmailAsync(new EmailViewModel(new string[] { _user.Email }, "Change Password - Template", "PASSWORD-CHANGED"), new string[] { _user.Name });

            return(true);
        }
示例#3
0
        public UserResponseAuthenticateViewModel Authenticate(UserRequestAuthenticateViewModel user)
        {
            User _user = repository.GetByEmailAndPassword(user.Email, UtilsService.EncryptPassword(user.Password));

            if (_user == null)
            {
                throw new ApiException("Email/Password not found", HttpStatusCode.NotFound);
            }

            if (!_user.IsAuthorised)
            {
                throw new ApiException("Your account is not activate yet.", HttpStatusCode.NotFound);
            }

            string token = tokenService.GenerateToken(mapper.Map <ContextUserViewModel>(_user));

            UserResponseAuthenticateViewModel _userResponse = mapper.Map <UserResponseAuthenticateViewModel>(_user);

            _userResponse.Token = token;

            return(_userResponse);
        }
示例#4
0
        public bool Post(UserRequestCreateAccountViewModel user, string host)
        {
            ValidationService.ValidEmail(user.Email);
            ValidationService.ValidPassword(user.Password, user.PasswordConfirm);

            if (repository.GetByEmail(user.Email) != null)
            {
                throw new ApiException("Email not found", HttpStatusCode.Conflict);
            }

            Profile _profile = profileRepository.GetDefault();

            if (_profile == null)
            {
                throw new ApiException("Your account can't be registered because there is no default profile.", HttpStatusCode.Unused);
            }

            try
            {
                User _user = mapper.Map <User>(user);
                _user.ProfileId = _profile.Id;
                _user.Code      = UtilsService.GenerateCode(8);

                repository.Create(_user);

                string _generateUrlEmail = UtilsService.GenerateURL(_user.Code, _user.Email, host);

                emailSender.SendEmailAsync(new EmailViewModel(new string[] { _user.Email }, "Account Created - Template", "ACCOUNT-CREATED"), new string[] { _user.Name, _generateUrlEmail });

                return(true);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex.Message, HttpStatusCode.BadRequest);
            }
        }