Exemplo n.º 1
0
        public static Guid CreateAuthenticationControl(Guid userId, AuthOrigin origin)
        {
            var token = Guid.NewGuid();

            AuthenticationControlRepository.Get().InsertAuthControl(userId, token, origin, true);

            return(token);
        }
Exemplo n.º 2
0
        public void InsertAuthControl(Guid userId, Guid token, AuthOrigin origin, bool manterConectado)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("@usuarioid", userId, System.Data.DbType.Guid);
            parameters.Add("@token", token, System.Data.DbType.Guid);
            parameters.Add("@dataregistro", DateTime.UtcNow, System.Data.DbType.DateTime);
            parameters.Add("@origem", origin, System.Data.DbType.Int16);
            parameters.Add("@manterconectado", manterConectado, System.Data.DbType.Int16);

            Execute(INSERT_AUTH_CONTROL, parameters);
        }
Exemplo n.º 3
0
        public static UserEntity Authenticate(string email, string password, AuthOrigin origin)
        {
            UserEntity user;

            user = UserRepository.Get().GetUserAuth(email);

            if (user == null)
            {
                throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.BadRequest, Messages.USER_INVALID);
            }

            switch (origin)
            {
            case AuthOrigin.App:
                if (user.UserType == UserType.Administrator)
                {
                    throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.BadRequest, Messages.USER_INVALID);
                }
                break;

            case AuthOrigin.Web:
                if (user.UserType == UserType.SalesPerson ||
                    user.UserType == UserType.SecundarySalesPerson)
                {
                    throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.BadRequest, Messages.USER_INVALID);
                }
                break;
            }

            if (ValidatePassword(password, user.PasswordSalt, user.Password))
            {
                user.Password     = string.Empty;
                user.PasswordSalt = string.Empty;
                return(user);
            }
            else
            {
                throw new ExceptionWithHttpStatus(System.Net.HttpStatusCode.BadRequest, Messages.USER_INVALID);
            }
        }
Exemplo n.º 4
0
 public UserEntity Authenticate(string email, string password, AuthOrigin origin)
 {
     return(UserBusiness.Authenticate(email, password, origin));
 }
Exemplo n.º 5
0
 public Guid CreateAuthenticationControl(Guid userId, AuthOrigin origin)
 {
     return(AuthenticationBusiness.CreateAuthenticationControl(userId, origin));
 }