| | 174 | |
| | 175 | /** Instantiate a user object |
| | 176 | * @param $username The username of the user |
| | 177 | * @param $account_origin Network: The account origin |
| | 178 | * @param &$errMsg An error message will be appended to this if the username is not empty, but the user doesn't exist. |
| | 179 | * @return a User object, or null if there was an error |
| | 180 | */ |
| | 181 | public static function getUserByUsernameOrEmailAndOrigin($usernameOrEmail, Network $account_origin, &$errMsg = null) { |
| | 182 | $db = AbstractDb::getObject(); |
| | 183 | $object = null; |
| | 184 | |
| | 185 | $username_str = $db->escapeString($usernameOrEmail); |
| | 186 | $comparison = ($account_origin->getUsernamesCaseSensitive()? '=': 'ILike'); |
| | 187 | $account_origin_str = $db->escapeString($account_origin->getId()); |
| | 188 | $db->execSqlUniqueRes("SELECT user_id FROM users WHERE (username {$comparison} '$username_str' OR email ILike '$username_str') AND account_origin = '$account_origin_str'", $user_info, false); |
| | 189 | |
| | 190 | if ($user_info != null) { |
| | 191 | $object = self::getObject($user_info['user_id']); |
| | 192 | } |
| | 193 | else if (!empty($usernameOrEmail)) { |
| | 194 | $errMsg .= sprintf(_("There is no user with username or email %s"),$usernameOrEmail); |
| | 195 | } |
| | 196 | return $object; |
| | 197 | } |