Example #1
0
        public static ServerResponse loginUser(string email, string password)
        {
            long id = SqliteHandler.getUserId(email);

            if (id == -1)
            {
                //return a failure with an error message an no payload
                return(new ServerResponse(false, "email doesn't exist", null));
            }
            string realPassword = SqliteHandler.getUserPassword(id);

            //hash password
            password = hashPassword(password);

            if (realPassword != null && realPassword.Equals(password))
            {
                UserModel user = SqliteHandler.getUser(id);
                return(new ServerResponse(true, "user login successfull", user));
            }
            //if not successful
            else
            {
                //...
                //sql call returns no match
                return(new ServerResponse(false, "password doesn't match", null));
            }
        }
Example #2
0
        public static void emailAll()
        {
            long[] ids = SqliteHandler.getAllUserIds();
            for (int i = 0; i < ids.Length; i++)
            {
                string[] stocks   = SqliteHandler.getAllMail(ids[i]);
                string   contents = "";
                for (int j = 0; j < stocks.Length; j++)
                {
                    string[]       fields = { "*" };
                    ServerResponse sr     = StockUtilities.getQuote(stocks[j], fields);

                    if (sr.payload != null)
                    {
                        contents += sr.payload.ToString();
                    }
                }

                UserModel user = SqliteHandler.getUser(ids[i]);

                if (stocks.Length != 0)
                {
                    sendEmail(user.email, "Stock Update", contents);
                }
                else
                {
                    Console.WriteLine(user.email + " was skipped as they had no subscriptions");
                }
            }
        }
Example #3
0
        public static ServerResponse getUserDashboard(long userID)
        {
            UserModel existing = SqliteHandler.getUser(userID);

            if (existing == null)
            {
                return(new ServerResponse(false, "user not found", null));
            }

            return(new ServerResponse(true, "dashboard loaded successfully", existing.widgetList));
        }
Example #4
0
        public static ServerResponse addUserWidget(long userId, WidgetModel widget)
        {
            UserModel user = SqliteHandler.getUser(userId);

            if (user == null)
            {
                return(new ServerResponse(false, "user could not be found", null));
            }

            long wid = SqliteHandler.createWidget(userId, widget);

            return(new ServerResponse(true, "widget was successfully created", wid));
        }
Example #5
0
        public static ServerResponse logoutUser(long userID)
        {
            //for now just verify that a user exists to be criteria
            UserModel user = SqliteHandler.getUser(userID);

            if (user != null)
            {
                return(new ServerResponse(true, "user logged out", null));
            }
            else
            {
                return(new ServerResponse(false, "unable to log out", null));
            }
        }
Example #6
0
        //functions should preferably be static as they should be stateless
        public static ServerResponse createUser(string email, string password, string passwordConf)
        {
            //check to see if the email is already taken
            long id = SqliteHandler.getUserId(email);

            if (id != -1)
            {
                //return a failure with an error message an no payload
                return(new ServerResponse(false, "email already exists", null));
            }
            //check to see if passwords match
            if (password.Equals(passwordConf) == false)
            {
                return(new ServerResponse(false, "passwords do not match", null));
            }

            //Down the line do some call to send an email to the user, for now do nothing
            //grab the user id of the created user


            //hash the password
            password = hashPassword(password);


            id = SqliteHandler.createUser(email, password);
            if (id == -1)
            {
                //there was some failure
                return(new ServerResponse(false, "there was an error creating the user", null));
            }


            UserModel newUser = SqliteHandler.getUser(id); //grab the created user

            if (newUser != null)
            {
                //return a success with a success message and put the user into the payload
                return(new ServerResponse(true, "account created successfully", newUser));
            }
            else
            {
                //there was some failure
                return(new ServerResponse(false, "there was an error grabbing the created the user", null));
            }
        }