コード例 #1
0
ファイル: RestPincode.php プロジェクト: httvncoder/151722441
 public function postValidPincode()
 {
     if (!Auth::check()) {
         return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500);
     }
     if (!Input::has('pincode')) {
         return;
     }
     $rules = array('pincode' => 'required|alpha_num|size:4');
     if ($response = self::valid($rules)) {
         return Response::json($response);
     }
     //$phone_number = Input::get('phone_number');
     $user_id = Auth::getUser()->id;
     $pincode = Input::get('pincode');
     // Get pincode inactive
     $check = Pincode::getLastPincodeInActive($user_id, $pincode);
     if ($check && !empty($check->phone_number)) {
         // Exists pincode inactive in db
         if (Pincode::ActivePincode($check->phone_number)) {
             // Update user has actived
             $user = User::where('id', $user_id)->update(array('is_validated' => 1, 'phone_number' => $check->phone_number));
             if (isset($user->errors)) {
                 return Response::json(response_message(400, $user->errors()->first()), 400);
             }
         }
         return Response::json(response_message(200));
     } else {
         return Response::json(response_message(1006));
     }
 }
コード例 #2
0
 protected function loadData()
 {
     $days = $this->property('days');
     if (!$days) {
         throw new ApplicationException('Invalid days value: ' . $days);
     }
     // all accesses for last month
     $items = User::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get();
     // parse data
     $all = [];
     foreach ($items as $item) {
         // date
         $timestamp = strtotime($item->created_at) * 1000;
         $day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
         if (isset($all[$day])) {
             $all[$day][1]++;
         } else {
             $all[$day] = [$timestamp, 1];
         }
     }
     // count all
     $all_render = [];
     foreach ($all as $a) {
         $all_render[] = [$a[0], $a[1]];
     }
     return $all_render;
 }
コード例 #3
0
ファイル: UserPassword.php プロジェクト: grohman/oc-idwidgets
 /**
  * Execute the console command.
  * @throws Exception
  */
 public function fire()
 {
     $login = $this->argument('login');
     if ($this->rainlab) {
         $rainlab = (bool) $this->option('rainlab');
     } else {
         $rainlab = false;
     }
     if ($rainlab) {
         $user = \RainLab\User\Models\User::where('email', '=', $login)->orWhere('username', '=', $login)->first();
     } else {
         $user = User::whereLogin($login)->first();
     }
     if (!$user) {
         return $this->error('User not found');
     }
     $password = $this->option('password');
     if ($rainlab) {
         $login = '******' . $login;
     } else {
         $login = '******' . $login;
     }
     if ($password == null) {
         $password = $this->ask('Set password for ' . $login . ' (or press Enter to skip)');
     }
     if ($password == null) {
         $password = Str::random(5);
     }
     $user->update(['password' => $password, 'password_confirmation' => $password]);
     $message = "\n  -> new password for " . $login . ": ";
     $this->comment($message . $password);
     return;
 }
コード例 #4
0
ファイル: Merge.php プロジェクト: aydancoskun/octobercms
 public function onDeleteSource()
 {
     $userFrom = user::where('email', post('sourceOldEmail'))->find(post('sourceId'));
     if (!$userFrom) {
         return null;
     }
     $surname = $userFrom->surname;
     $name = $userFrom->name;
     $userFrom->delete();
     return ['#layout-flash-messages' => '<p data-control="flash-message" class="flash-message success" data-interval="5">User ' . $name . ' ' . $surname . ' has been deleted from the system.</p>'];
 }
コード例 #5
0
ファイル: UserEvents.php プロジェクト: abnmt/oc-mrc-plugin
 /**
  * Update Events from CRM
  */
 public function onUpdateFromCrm()
 {
     $crmuserevents = CRMUserEvent::isNotUpdated()->with(['user', 'event'])->get();
     \CW::info(['userevents' => $crmuserevents]);
     if (count($crmuserevents) == 0) {
         Flash::info("No UserEvents to Create/Update");
         // echo "ERROR!";
         return;
     }
     $crmuserevents->each(function ($userevent) {
         if ($userevent->user && $userevent->event) {
             \CW::info([$userevent]);
             $cmsuser = User::where('email', $userevent->user->email)->first();
             $cmsevent = Event::where('crm_event_id', $userevent->event->id)->with('course')->first();
             $cmscourse = $cmsevent->course;
             $cmsusereventstate = UserEventState::where('crm_state_id', $userevent->state_id)->first();
             // $cmsuserevent = UserEvent::firstOrNew(['crm_event_id' => $userevent->event->id, 'user_id' => $cmsuser->id]);
             // $cmsuserevent = $cmsuser->userevents()
             // $cmsuserevent = $cmsuserevent
             $cmsuserevent = UserEvent::where('user_id', $cmsuser->id)->where('event_id', $cmsevent->id)->first();
             if (!$cmsuserevent) {
                 $cmsuserevent = new UserEvent();
             }
             \CW::info([$cmsuser, $cmsevent, $cmscourse, $cmsuserevent, $cmsusereventstate]);
             // if (!$cmsuser) {
             //     Log::warning("CMSUser is NULL\n");
             // }
             // if (!$cmsevent) {
             //     Log::warning("CMSEvent is NULL\n");
             // }
             // if (!$cmscourse) {
             //     Log::warning("CMSCourse is NULL\n");
             // }
             // if (!$cmsuserevent) {
             //     Log::warning("CMSUserEvent is NULL\n");
             // }
             // if (!$cmsusereventstate) {
             //     Log::warning("CMSUserEventState is NULL\n");
             // }
             $cmsuserevent->user()->associate($cmsuser);
             $cmsuserevent->course()->associate($cmscourse);
             $cmsuserevent->state()->associate($cmsusereventstate);
             $cmsuserevent->event()->associate($cmsevent);
             $cmsuserevent->fill(['course_type_id' => $cmscourse->course_type_id, 'course_category_id' => $cmscourse->course_category_id, 'crm_event_id' => $userevent->event->id]);
             \CW::info([$cmsuserevent]);
             $cmsuserevent->save();
             $userevent->update(['is_updated' => true]);
         }
     });
     Flash::success("UserEvents is update");
 }
コード例 #6
0
 /**
  * Migrate auth from Kohana to Laravel/OctoberCMS.
  *
  * @param  string  $login     Username or email
  * @param  string  $password
  * @return  bool  Migrated
  */
 public static function migrate($login, $password)
 {
     if (!$login || !$password) {
         return false;
     }
     if (!($user = User::where('username', $login)->orWhere('email', $login)->first())) {
         return false;
     }
     if (!$user->password && self::check($password, $user->password_kohana)) {
         $user->password = $user->password_confirmation = $password;
         $user->forceSave();
         return true;
     }
     return false;
 }
コード例 #7
0
 public function onPrintCard()
 {
     $locationId = post('printerLocation');
     if (empty($locationId)) {
         Flash::error(Lang::get('dma.friends::lang.user.memberCardLocation'));
         return;
     }
     $location = Location::find($locationId);
     $user = post('User');
     $user = User::where('email', '=', $user['email'])->first();
     try {
         $manager = new PrintManager($location, $user);
         $manager->printIdCard();
         Flash::info(Lang::get('dma.friends::lang.user.memberCard', ['title' => $location->title]));
     } catch (SystemException $e) {
         Flash::error($e->getMessage());
     }
 }
コード例 #8
0
 protected function loadData()
 {
     $days = $this->property('days');
     if (!$days) {
         throw new ApplicationException('Invalid days value: ' . $days);
     }
     // all accesses for last month
     $items = User::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get();
     // parse data
     $all = $this->sortItemsToDays($items);
     // we need at least two days, to display chart
     if (sizeof($all) == 1) {
         $day = reset($all);
         $date = Carbon::createFromFormat('Y-m-d', $day['date'])->subDays(1);
         $dateFormated = $date->format('Y-m-d');
         $all[$dateFormated] = ['timestamp' => $date->timestamp * 1000, 'date' => $dateFormated, 'count' => 0];
     }
     // count all
     $all_render = [];
     foreach ($all as $a) {
         $all_render[] = [$a['timestamp'], $a['count']];
     }
     return $all_render;
 }
コード例 #9
0
 public function onNotificationsReady()
 {
     Postman::listen(['sms', 'regex' => '/.*/'], function (IncomingMessage $message) {
         // Find user using mobile phone
         $phoneUser = $message->getFrom();
         // Getting first user match. Assuming that phone is
         // unique in the database
         if ($user = User::where('phone', $phoneUser)->orWhere('phone', str_replace('+1', '', $phoneUser))->first()) {
             // Get code from message
             $params['code'] = $code = $message->getContent();
             // process Activity code first
             if (!($activity = ActivityCode::process($user, $params))) {
                 // Not found activity with that code.
                 // Trying if is a object assession number
                 $activity = LikeWorkOfArt::process($user, $params);
             }
             // Send SMS and kiosk notification
             $typeMessage = $activity ? 'successful' : 'error';
             $template = 'activity_code_' . $typeMessage;
             Postman::send($template, function (NotificationMessage $notification) use($user, $code, $activity) {
                 // Reply to same phone number
                 $notification->to($user, $user->name);
                 // Send code and activity just in case we want to use in the template
                 $notification->addData(['code' => $code, 'activity' => $activity, 'viaSMS' => true]);
                 // Determine the content of the message
                 $holder = $activity ? 'activityMessage' : 'activityError';
                 $message = Session::pull($holder);
                 if (is_array($message)) {
                     foreach ($message as $m) {
                         $notification->message($m);
                     }
                 } else {
                     $notification->message($message);
                 }
             }, ['sms', 'kiosk']);
             Log::debug('Incoming SMS', ['user' => $user, 'code' => $code, 'activity' => $activity]);
         } else {
             Postman::send('simple', function (NotificationMessage $notification) use($phoneUser) {
                 $user = new User();
                 $user->phone = $phoneUser;
                 // Reply to same phone number
                 $notification->to($user, $user->name);
                 $notification->message(Lang::get('dma.friends::lang.user.memberPhoneNotFound'));
             }, ['sms']);
         }
     });
 }
コード例 #10
0
ファイル: UserLogin.php プロジェクト: janusnic/OctoberFriends
 /**
  * Verify if the given user mail is not already register
  */
 public function onAvailableUser()
 {
     $email = post('email');
     $data = ['available' => true];
     if (User::where('email', $email)->count() > 0) {
         $data['available'] = false;
     }
     return $data;
 }
コード例 #11
0
 /**
  * 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.frontendmailsender::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.frontendmailsender::lang.test.sent'));
     }
     /**
      * Getting users count in this group
      * */
     $users_count = DB::table('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('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']->name);
             });
         }
         /**
          * Success Message
          * */
         Flash::success(Lang::get('lilessam.frontendmailsender::lang.sent') . $users_count . Lang::get('lilessam.frontendmailsender::lang.users'));
     } else {
         /**
          * Warning message that there's no users in this group
          * */
         Flash::warning(Lang::get('lilessam.frontendmailsender::lang.nousers'));
     }
 }
コード例 #12
0
 /**
  * Successful login with Facebook.
  */
 public function onLoginWithFacebook()
 {
     $newUser = false;
     try {
         $accessToken = GraphAPI::instance()->getUserAccessToken(true);
         $response = GraphAPI::instance()->get('/me', ['id', 'email', 'name'], $accessToken);
         $facebookUser = $response->getGraphUser();
     } catch (SystemException $e) {
         Flash::error('Facebook login failed.');
         return;
     }
     $externalUser = UserExternalModel::facebook([$facebookUser->getId()])->first();
     if (!$externalUser) {
         // No user found by Facebook user id
         $user = UserModel::where('email', '=', $facebookUser->getEmail())->first();
         if (!$user) {
             // No user found by email either, sign up
             $newUser = true;
             $password = uniqid();
             $signup = ['username' => $facebookUser->getName(), 'name' => $facebookUser->getName(), 'email' => $facebookUser->getEmail(), 'password' => $password, 'password_confirmation' => $password];
             try {
                 $user = Auth::register($signup, true);
             } catch (ModelException $e) {
                 Log::error('Facebook sign up failed: ' . $e->getMessage());
                 $signup['username'] .= rand(1000, 9999);
                 try {
                     $user = Auth::register($signup, true);
                 } catch (ModelException $e) {
                     Log::error('Facebook sign up failed: ' . $e->getMessage());
                     Flash::error(Lang::get('klubitus.facebook::lang.register.register_failed'));
                     return;
                 }
             }
         }
         UserExternalModel::create(['user_id' => $user->id, 'provider' => UserExternalModel::PROVIDER_FACEBOOK, 'external_user_id' => $facebookUser->getId(), 'token' => $accessToken->getValue(), 'expires_at' => $accessToken->getExpiresAt()]);
     } else {
         $user = $externalUser->user;
     }
     Auth::login($user, true);
     if (post('redirect', true)) {
         if ($newUser) {
             return Redirect::to(post('redirect_signup', URL::previous() ?: Request::fullUrl()));
         } else {
             return Redirect::to(post('redirect_login', URL::previous() ?: Request::fullUrl()));
         }
     }
 }
コード例 #13
0
 /**
  * Ajax handler for searching users
  */
 public function onSearchUser()
 {
     // Suggest exsiting members
     if (($search = post('newUser')) != '') {
         $users = User::where($this->getLoginAttr(), 'LIKE', "{$search}%")->orWhere('name', 'LIKE', "{$search}%")->take($this->property('maxUserSuggestions'))->get();
         /*
         $users = User::groups()
                 ->wherePivot('membership_status', '<>', UserGroup::MEMBERSHIP_ACCEPTED )
                 ->with('groups')
                 ->whereHas('groups', function($query){
                     $query->where('is_active', true);
                 })
                
                 ->get();
         */
         // Updated list of users and other vars
         $this->prepareVars(null, ['search' => $search, 'users' => $users]);
     }
 }
コード例 #14
0
 /**
  * Ajax handler for adding members
  */
 public function onAddMember()
 {
     // refresh current step
     $this->currentStep = self::STEP_MEMBERS;
     if (($groupId = post('groupId')) != '') {
         // Add to group
         $group = $this->getGroup($groupId);
         if (($username = post('username')) != '') {
             $user = User::where($this->getLoginAttr(), '=', $username)->first();
             if ($user) {
                 \Log::info(UserGroup::getActiveMembershipsCount($user));
                 try {
                     $added = $group->addUser($user);
                     if (!$added) {
                         if ($user->getKey() == $group->owner->getKey()) {
                             $message = Lang::get('dma.friends::lang.groups.ownerCanBeMember');
                             Flash::error($message);
                         }
                     }
                 } catch (\Exception $e) {
                     Flash::error($e->getMessage());
                 }
             } else {
                 $message = Lang::get('dma.friends::lang.exceptions.userNotFound');
                 Flash::error($message);
             }
         }
         // Updated list of users and other vars
         $this->prepareVars($group);
     }
 }
コード例 #15
0
 /**
  * Lookup user by barcode id
  *
  * @param string $id
  * An id to lookup by barcode id
  *
  * @return User $user
  * A RainLab\User\Model\User object
  */
 private static function isBarcode($id)
 {
     $user = User::where('barcode_id', $id)->first();
     if ($user) {
         return $user;
     }
     return false;
 }
コード例 #16
0
 /**
  * Get all users
  *
  * @return mixed
  */
 public function getAllUsers()
 {
     return User::where('is_activated', true)->get();
 }