protected function findAuthorFromEmail($data) { if (!($email = array_get($data, 'email', $this->default_author))) { return null; } if (isset($this->authorEmailCache[$email])) { return $this->authorEmailCache[$email]; } $author = AuthorModel::where('email', $email)->first(); return $this->authorEmailCache[$email] = $author; }
/** * Sending Mail * */ public function onSendMail() { /** * Getting form results * */ $group_id = post('group'); $subject = post('subject'); $msg = post('message'); $test_email = post('testEmail'); /** * Checking if there's no data * */ if ($subject == "" || $msg == "") { return Flash::warning(Lang::get('lilessam.mailsender::lang.error_nodata')); } /** * Striping tags for the plain version of mail * */ $msgPlain = strip_tags(post('message')); /** * Setting vars array for mail template * */ $vars = ['subject' => $subject, 'msg' => $msg, 'msgPlain' => $msgPlain]; /** * Check if the administrator want to send only a test message * */ if ($test_email != "") { //email and subject array $array = ['email' => $test_email, 'subject' => $subject]; //Sending mail Mail::send(['text' => $msgPlain, 'html' => $msg, 'raw' => true], $vars, function ($message) use($array) { $message->subject($array['subject']); $message->to($array['email'], "Test Reciever"); }); /** * Success message * */ return Flash::success(Lang::get('lilessam.mailsender::lang.test.sent')); } /** * Getting users count in this group * */ $users_count = DB::table('backend_users_groups')->where('user_group_id', $group_id)->count(); /** * Checking if there's users in the group * */ if ($users_count != 0) { //Fetching users $users_ids = DB::table('backend_users_groups')->where('user_group_id', $group_id)->get(); /** * Looping to send mail to every user * */ foreach ($users_ids as $user_id) { //The user $user = User::where('id', $user_id->user_id)->first(); //User and subject array $array = ['user' => $user, 'subject' => $subject]; //Sending mail Mail::send(['text' => $msgPlain, 'html' => $msg, 'raw' => true], $vars, function ($message) use($array) { $message->subject($array['subject']); $message->to($array['user']->email, $array['user']->login); }); } /** * Success Message * */ Flash::success(Lang::get('lilessam.mailsender::lang.sent') . $users_count . Lang::get('lilessam.mailsender::lang.users')); } else { /** * Warning message that there's no users in this group * */ Flash::warning(Lang::get('lilessam.mailsender::lang.nousers')); } }
public function index() { # CHECK SETTINGS ARE DEFINED $this->checkSettings(['google_client_id', 'google_client_secret']); # CREATE GOOGLE CLIENT $client = new Google_Client(); $client->setClientId(Settings::get('google_client_id')); $client->setClientSecret(Settings::get('google_client_secret')); $client->setRedirectUri(Backend::url('martin/ssologin/google')); $client->setScopes('email'); # HANDLE LOGOUTS if (Input::has('logout')) { Session::forget('access_token'); return; } # AUTHENTICATE GOOGLE USER if (Input::has('code')) { $client->authenticate(Input::get('code')); Session::put('access_token', $client->getAccessToken()); } # SET ACCESS TOKEN OR GET A NEW ONE if (Session::has('access_token')) { $client->setAccessToken(Session::get('access_token')); } else { $authUrl = $client->createAuthUrl(); // Redirect::to() doesn't work here. Send header manually. header("Location: {$authUrl}"); exit; } # PARSE USER DETAILS if ($client->getAccessToken()) { Session::put('access_token', $client->getAccessToken()); $token_data = $client->verifyIdToken(); } # FORGET ACCESS TOKEN Session::forget('access_token'); # CHECK MAIL EXISTS if (!isset($token_data['email'])) { # RECORD FAILED LOGIN $log = new Log(); $log->provider = 'Google'; $log->result = 'failed'; $log->email = $email; $log->ip = Request::getClientIp(); $log->save(); Flash::error(trans('martin.ssologin::lang.errors.google.invalid_user')); return Backend::redirect('backend/auth/signin'); } # FIND USER BY EMAIL $email = $token_data['email']; $user = User::where('email', $email)->first(); # IF NO USER, GET BACK TO LOGIN SCREEN if (!$user) { # RECORD FAILED LOGIN $log = new Log(); $log->provider = 'Google'; $log->result = 'failed'; $log->email = $email; $log->ip = Request::getClientIp(); $log->save(); Flash::error(trans('martin.ssologin::lang.errors.google.invalid_user')); return Backend::redirect('backend/auth/signin'); } # LOGIN USER ON BACKEND BackendAuth::login($user, true); # RECORD SUCCESSFUL LOGIN $log = new Log(); $log->provider = 'Google'; $log->result = 'successful'; $log->user_id = $user->id; $log->email = $email; $log->ip = Request::getClientIp(); $log->save(); // Load version updates UpdateManager::instance()->update(); // Log the sign in event AccessLog::add($user); // Redirect to the intended page after successful sign in return Backend::redirectIntended('backend'); }
public function getAuthorInfo($id) { $user = BackendUserModel::where('id', $id)->first(); if ($user->avatar) { $user->image = $user->avatar->getThumb(100, 100, ['mode' => 'crop']); } return $user; }
public function formAfterDelete($model) { \Backend\Models\User::where('team_id', $model->id)->update(['team_id' => 0]); }