Exemplo n.º 1
0
        public HttpResponseMessage GetDashboardFeed([FromBody] string access_key)
        {
            SLW_DatabaseInfo db        = new SLW_DatabaseInfo();
            Dashboard        dashboard = new Dashboard();
            KeyDetail        detail    = db.GetKeyDetail(access_key);

            if (detail.data_present)
            {
                db.CheckForApplicationUpdates(detail.username);
                dashboard = db.GetDashboardData(detail.username);
                return(Request.CreateResponse(HttpStatusCode.OK, dashboard));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid key"));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Login([FromBody] Models.Login login)
        {
            Utilities.FileManager.GetEmailKey();
            Utilities.PasswordManager mgr = new Utilities.PasswordManager();
            SLW_DatabaseInfo          db  = new SLW_DatabaseInfo();

            if (login != null)
            {
                if (db.CheckUserExist(login.username))
                {
                    UserCredentials credentials = db.GetUserCredentials(login.username);
                    bool            passed      = mgr.VerifyCredentials(login.password, credentials.hash);

                    if (passed)
                    {
                        string access_key = mgr.GenerateNewAccessKey(login.username);
                        db.SetNewAccessKey(login.username, access_key);
                        db.SaveActivity(new UserActivity(login.username, Commons.Constants.ACTIVITY_LOGIN, "login successful", "", 1));
                        db.CheckForApplicationUpdates(login.username);
                        return(Request.CreateResponse(HttpStatusCode.OK, new Models.LoginResult("credentials verified", access_key, credentials.user_role, credentials.name, login.username)));
                    }
                    else
                    {
                        db.SaveActivity(new UserActivity(login.username, Commons.Constants.ACTIVITY_LOGIN, "incorrect credentials. login failed", "", 1));
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, new Models.LoginResult("incorrect credentials", "", -1, "", login.username)));
                    }
                }
                else
                {
                    db.SaveActivity(new UserActivity(login.username, Commons.Constants.ACTIVITY_LOGIN, "invalid user", "", 1));
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, new LoginResult("invalid user", "", -1, "", login.username)));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new LoginResult("bad request", "", -1, "", login.username)));
            }
        }