public function actionCancel() { $request = Yii::app()->request; $key = $request->getParam('key', null); if ($key) { $found = RecoveryRequest::model()->findByAttributes(array('reqkey' => $key)); if ($found) { // prevent any further attempts $found->delete(); } } $this->render('cancel'); }
public static function generateRequest($user) { $req = RecoveryRequest::model()->findByAttributes(array('id_user' => $user->id)); if (!$req) { $req = new RecoveryRequest(); $req->id_user = $user->id; } // only allow 1 request per hour if ($req->create_time) { if (time() - $req->create_time < 1 * 60 * 60) { return RecoveryRequest::GENERATE_WAIT; } } $req->reqkey = $req->generateRecoveryKey($user); if (!$req->save()) { Yii::log(var_dump($req->getErrors()), 'error'); return RecoveryRequest::GENERATE_ERR; } return RecoveryRequest::GENERATE_OK; }