コード例 #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));
            }
        }
コード例 #2
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));
            }
        }