public HttpResponseMessage Login(string Email, string Senha)
        {
            if (Email == null || Senha == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest, "Login Inválido");

            try {

                var usuario = UsuarioBO.GetUserByCredentials(Email, Senha);

                if(usuario == null)
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "Login Inválido");

                usuario.Token = Encryption.CreateToken(usuario);

                UsuarioBO.Save<Usuario>(usuario);

                var encriptObj = new EncryptionObject(usuario.Id, usuario.Token);
                var tk = Encryption.Base64Encode(encriptObj);

                return Request.CreateResponse(HttpStatusCode.OK, tk);

            }
            catch(Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
Esempio n. 2
0
 public static string Base64Encode(EncryptionObject obj)
 {
     string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
     var buffer = Encoding.UTF8.GetBytes(json);
     return Convert.ToBase64String(buffer);
 }