Beispiel #1
0
        public IHttpActionResult DeleteAuth(int id, int loggedId, string sessionKey)
        {
            Constants.VerifyUserErrors error = AuthHandler.VerifyUserSession(sessionKey, loggedId, db);
            Auth auth = db.Auths.Find(id);

            if (error == Constants.VerifyUserErrors.OK)
            {
                if (auth == null)
                {
                    return(NotFound());
                }

                if (auth.UserID != 0)
                {
                    AuthHandler.DeleteUserAuth(db, auth);
                    User foundUser = db.Users.FirstOrDefault(u => u.ID == auth.UserID);
                    if (foundUser != null)
                    {
                        User loggedUser = db.Users.FirstOrDefault(u => u.ID == loggedId);
                        if (loggedUser != null)
                        {
                            LogHandler.CreateLogEntry(db, loggedId, $"The user {loggedUser.Name} (ID: {loggedId}) has deleted the login information for {foundUser.Name} (ID: {foundUser.ID})", (int)LogHandler.RequestTypes.DELETE);
                        }
                    }

                    return(Ok(auth));
                }

                auth.UserID = -1;
                return(Ok(auth));
            }
            return(StatusCode(CommonMethods.StatusCodeReturn(error)));
        }