Ejemplo n.º 1
0
        // PUT: api/Login/5
        public async Task <IHttpActionResult> PostAsync([FromBody] Authentication login)
        {
            IHttpActionResult response = null;
            AuthenticatedUser authUser;

            try
            {
                authUser = repository.AuthenticateUser(login);
                if (authUser == null)
                {
                    response = Content(HttpStatusCode.NotFound, "User not found");;
                }
                else
                {
                    var token = await TokenGenerator.Generate();

                    authUser.Token = token;
                    TokenStorage.GetInstance().SaveToken(authUser.Token);
                    response = Ok(authUser);
                }
            }
            catch (Exception ex)
            {
                // Write the excption to a log
                response = InternalServerError();
            }

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> NewToken(Account account)
        {
            UserDTO user;

            try
            {
                user = repository.AuthenticateUser(account);
                Authentication auth = null;
                if (user == null)
                {
                    response = NotFound();
                }
                else
                {
                    var token = await TokenGenerator.Generate();

                    auth = new Authentication {
                        token = token, user = user
                    };
                    TokenStorage.GetInstance().SaveToken(auth.token);
                    response = Ok(auth);
                }
            }
            catch (Exception ex)
            {
                // Write the excption to a log
                response = InternalServerError();
            }

            return(response);
        }
Ejemplo n.º 3
0
 public IHttpActionResult PutAsync([FromBody] Model.AuthenticatedUser login)
 {
     try
     {
         TokenStorage.GetInstance().RemoveToken(login.Token);
         AuthenticatedUser authUser = new AuthenticatedUser();
         return(Ok(authUser));
     }
     catch (Exception ex)
     {
         // Write the excption to a log
         return(InternalServerError());
     }
 }