/** * Validate user provided fields. * @param $data User provided fieds and id's of those fields that will be used for displaying error messages on client side. * @param bool $botProtection Should bot protection be validated or not * @return array Array with errors if there are some, empty array otherwise. */ public function validateUser($data, $botProtection = true) { $id = $data['fieldId']; $user = $data['userData']; $errors = array(); $validator = new ASValidator(); //check if email is not empty if ($validator->isEmpty($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_required')); } //check if username is not empty if ($validator->isEmpty($user['username'])) { $errors[] = array("id" => $id['username'], "msg" => ASLang::get('username_required')); } //check if password is not empty if ($validator->isEmpty($user['password'])) { $errors[] = array("id" => $id['password'], "msg" => ASLang::get('password_required')); } //check if password and confirm password are the same if ($user['password'] != $user['confirm_password']) { $errors[] = array("id" => $id['confirm_password'], "msg" => ASLang::get('passwords_dont_match')); } //check if email format is correct if (!$validator->emailValid($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_wrong_format')); } //check if email is available if ($validator->emailExist($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_taken')); } //check if username is available if ($validator->usernameExist($user['username'])) { $errors[] = array("id" => $id['username'], "msg" => ASLang::get('username_taken')); } if ($botProtection) { //bot protection $sum = ASSession::get("bot_first_number") + ASSession::get("bot_second_number"); if ($sum != intval($user['bot_sum'])) { $errors[] = array("id" => $id['bot_sum'], "msg" => ASLang::get('wrong_sum')); } } return $errors; }
/** * Validate data provided during user update * @param $data * @return array */ private function _validateUserUpdate($data) { $id = $data['fieldId']; $user = $data['userData']; $errors = array(); $validator = new ASValidator(); $userInfo = $this->getInfo(); if ($userInfo == null) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('user_dont_exist')); return $errors; } //check if email is not empty if ($validator->isEmpty($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_required')); } //check if username is not empty if ($validator->isEmpty($user['username'])) { $errors[] = array("id" => $id['username'], "msg" => ASLang::get('username_required')); } //check if password and confirm password are the same if (!$user['password'] == hash('sha512', '') && $user['password'] != $user['confirm_password']) { $errors[] = array("id" => $id['confirm_password'], "msg" => ASLang::get('passwords_dont_match')); } //check if email format is correct if (!$validator->emailValid($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_wrong_format')); } //check if email is available if ($user['email'] != $userInfo['email'] && $validator->emailExist($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_taken')); } //check if username is available if ($user['username'] != $userInfo['username'] && $validator->usernameExist($user['username'])) { $errors[] = array("id" => $id['username'], "msg" => ASLang::get('username_taken')); } return $errors; }
/** * Validate user provided fields. * @param $data User provided fieds and id's of those fields that will be used for displaying error messages on client side. * @param bool $botProtection Should bot protection be validated or not * @return array Array with errors if there are some, empty array otherwise. */ public function validateUser($data, $validateFor, $botProtection = true) { $id = $data['fieldId']; $user = $data['userData']; $errors = array(); $validator = new ASValidator(); //check if email is not empty if ($validator->isEmpty($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_required')); } //check if email format is correct if (!$validator->emailValid($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('email_wrong_format')); } //check if email is available if ($validateFor == "student") { if ($validator->studentemailExist($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('student_email_taken')); } } elseif ($validateFor == "franchise") { if ($validator->franchiseemailExist($user['email'])) { $errors[] = array("id" => $id['email'], "msg" => ASLang::get('franchise_email_taken')); } } if ($botProtection) { //bot protection $sum = ASSession::get("bot_first_number") + ASSession::get("bot_second_number"); if ($sum != intval($user['bot_sum'])) { $errors[] = array("id" => $id['bot_sum'], "msg" => ASLang::get('wrong_sum')); } } return $errors; }