public function createHash($user_id, $action, $config = null) { $hash = Str::random($this->hashLen()); if (ConfirmUser::findHash($hash)->exists()) { $hash = self::createHash($user_id, $action, $config); } else { $data = compact('user_id', 'hash', 'action', 'config'); //$record = ConfirmUser::firstOrNew(compact('user_id','action')); $record = ConfirmUser::CheckRecord($user_id, $action); if ($record->exists() && !$record->first()->update($data) || !$record->exists() && !ConfirmUser::create($data)) { throw new Exception\ConfirmModelSaveException('Error save or update model'); } } return $hash; }
public static function oldMail(\User $user, $oldMail = null) { $out = 'Incorrect email'; if (!empty($newMail) && is_scalar($oldMail)) { if (!\User::where('email', $oldMail)->where('id', '!=', $user->id)->exists()) { $user->email = $oldMail; $user->save(); $out = 'return old email'; } else { $out = 'Old email ' . $oldMail . ' adress is already in use'; } } ConfirmUser::where('action', 'newMail')->where('user_id', $user->id)->delete(); return $out; }
public function check($hash) { $out = null; if (is_scalar($hash)) { $confirumObj = ConfirmUser::findHash($hash); if (!$confirumObj->exists()) { throw new Exception\ConfirmHashNotFoundException('Confirm hash ' . $hash . ' not found'); } $confirumObj = $confirumObj->first(); if (is_callable($confirumObj->getCallback())) { $out = call_user_func($confirumObj->getCallback(), $confirumObj->user, $confirumObj->getConfigField()); $confirumObj->delete(); } else { throw new Exception\ConfirmCallbackException('Callback ' . $confirumObj->action . ' not found'); } } else { throw new Exception\ConfirmIncorrectHashException('Incorrect confirm hash'); } return $out; }