Example #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);
        }
Example #2
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);
            }
        }