Beispiel #1
0
        public StatusCodeResult ChangePassword([FromBody] UserInfoDTO data)
        {
            string email = "";

            // get users email from the token sent
            email = SessionController.sm.getEmail(data.authToken);

            // make sure user is authenticated
            if (SessionController.sm.ifTokenValid(data.authToken))
            {
                AccountCreator c = new AccountCreator();

                // check that passwords match and length is 8 or more
                if (data.password.Equals(data.password2) && data.password.Length > 7)
                {
                    // check that old password was correct
                    int status = AccountValidator.compareCredentials(email, data.currentPassword);

                    // if current password was valid, go through with password change
                    if (status == 1)
                    {
                        c.changePassword(data.password, email);
                        return(StatusCode(200));
                    }
                    else
                    {
                        return(StatusCode(400));
                    }
                }
                else
                {
                    return(StatusCode(400));
                }
            }
            else
            {
                return(StatusCode(401));
            }
        }
Beispiel #2
0
        public string ValidateCredentials([FromBody] UserInfoDTO data)
        {
            var DTO    = new UserInfoDTO();
            int status = AccountValidator.compareCredentials(data.email, data.password);

            if (status == 1)   //valid credentials
            {
                string token;
                // check to see if user has a token already
                if (SessionController.sm.ifUserExists(data.email))
                {
                    token = SessionController.sm.getToken(data.email);
                }
                else
                {
                    // generate token for user
                    SessionController.sm.updateToken(data.email);
                    token = SessionController.sm.getToken(data.email);
                }

                DTO.status = "200";                              //Set the status
                DTO        = DTO.getUserInfo(data.email, token); //Get the user info for return
                string output = JsonConvert.SerializeObject(DTO);

                return(output);
            }
            else if (status == 0)   //invalid credentials
            {
                DTO.status = "400";
                string output = JsonConvert.SerializeObject(DTO);
                return(output);
            }
            else    //Null error
            {
                DTO.status = "404";
                string output = JsonConvert.SerializeObject(DTO);
                return(output);
            }
        }