public async Task <LoginReturnDTO> Registration(MemberRegistrationDTO memberRegistration)
        {
            try
            {
                ValidatesRegistration(memberRegistration);

                Member member = new Member();
                member.Name       = memberRegistration.Name;
                member.UserName   = memberRegistration.UserName;
                member.Email      = memberRegistration.Email;
                member.SecretWord = _encrypt.EncryptPassword(memberRegistration.SecretWord);
                member.Active     = true;

                member = await _memberRepository.Insert(member);

                var token = _accessManager.GenerateToken(member);

                return(new LoginReturnDTO()
                {
                    Name = member.Name,
                    Email = member.Email,
                    Image = member.Image,
                    Adm = member.Adm,
                    Token = token
                });
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        public async Task <Member> ValidateCredentials(User user)
        {
            if (string.IsNullOrEmpty(user.UserName))
            {
                throw new ValidationException("Informe o nome de usuario."); // TODO: Alterar para o Midleware exception
            }
            if (string.IsNullOrEmpty(user.PassWord))
            {
                throw new ValidationException("Informe a senha."); // TODO: Alterar para o Midleware exception
            }
            user.PassWord = _encrypt.EncryptPassword(user.PassWord);
            var member = await _memberRepository.ValidateLogin(user);

            if (member == null)
            {
                throw new ValidationException("Usuario ou senha inválidos.");
            }

            return(member);
        }