00001 <?php
00002 class ResetPassword {
00009 private static function getReset($userId) {
00010 $oldReset = AuthResetPassword::getList(array(
00011 'userId' => $userId
00012 ), array(), array());
00013
00014 if(count($oldReset) > 0) {
00015 $reset = $oldReset[0];
00016 } else {
00017 $reset = new AuthResetPassword;
00018 $reset->userId = $userId;
00019 }
00020 return $reset;
00021 }
00022
00031 public static function sendEmail($username, $email, $resetPage) {
00032
00033 $user = AuthUser::getList(array(
00034 'username' => $username,
00035 'email' => $email
00036 ), array(), array());
00037
00038
00039 if(count($user) == 0) {
00040 return;
00041 }
00042 $user = $user[0];
00043
00044
00045 if($user->ldapUserId !== null) {
00046 self::renderTemplate('resetLdap', $user->email);
00047 }
00048
00049
00050 $reset = self::getReset($user->id);
00051
00052
00053 $hash = SRandom::hex(32);
00054 $reset->hash = $hash;
00055 $reset->commit();
00056
00057
00058 $values = array(
00059 'reseturl' => $resetPage . '?userId=' .$user->id . '&hash=' . $hash,
00060 'username' => $user->username
00061 );
00062 AuthEmail::renderTemplate('resetPassword', $user->email, $values);
00063 }
00064
00072 public static function check($userId, $hash) {
00073 $reset = AuthResetPassword::getList(array(
00074 'userId' => $userId,
00075 'hash' => $hash,
00076 '>=' => array(
00077 'requestTime' => date('Y-m-d H:i:s', time() - (SConfig::getOption('auth.resetPasswordTimeoutDays') * 24 * 60 * 60))
00078 )
00079 ), array(), array(), true);
00080
00081 return (bool)($reset > 0);
00082 }
00083
00089 public static function deleteRequest($userId) {
00090 $reset = new AuthResetPassword(array('userId'=>$userId));
00091 $reset->markForDeletion();
00092 $reset->commit();
00093 }
00094 }
00095 ?>