public function fetchUserDetails($ident, $type)
 {
     $search_cond = 'users.user_id = ' . $ident;
     if ($type == 'code') {
         $search_cond = 'users.user_code = ' . $ident;
     }
     $user_details = array();
     $user_details['err_msg'] = '';
     $user_details['own_profile'] = 'No';
     $udetails = User::whereRaw($search_cond)->first(array('users.first_name', 'users.id', 'users.last_name', 'users.email', 'users.activated', 'users.activated_at'));
     if (count($udetails) > 0) {
         $user_details['user_code'] = CUtil::setUserCode($udetails['id']);
         $user_details['email'] = $udetails['email'];
         $user_details['user_id'] = $user_id = $udetails['id'];
         $user_details['first_name'] = $udetails['first_name'];
         $user_details['last_name'] = $udetails['last_name'];
         $user_display_name = $udetails['first_name'] . ' ' . substr($udetails['last_name'], 0, 1);
         $user_details['display_name'] = ucwords($user_display_name);
         $user_details['activated_at'] = $udetails['activated_at'];
         $user_details['activated'] = $udetails['activated'];
     } else {
         $user_details['err_msg'] = 'No such user found';
     }
     return $user_details;
 }
 public function index()
 {
     $totalQuizzesCount = Quiz::count();
     $totalUsersCount = User::count();
     $todayQuizzesCount = Quiz::whereRaw('DATE(created_at) = DATE(NOW())')->count();
     $todayUsersCount = User::whereRaw('DATE(created_at) = DATE(NOW())')->count();
     $overallActivities = QuizUserActivity::groupBy('type')->havingRaw("type in ('attempt', 'share')")->select('type', DB::raw('count(*) as count'))->get()->toArray();
     $overallStats = array();
     foreach ($overallActivities as $activity) {
         $overallStats[$activity['type']] = $activity['count'];
     }
     $overallStats['quizzes'] = $totalQuizzesCount;
     $overallStats['users'] = $totalUsersCount;
     $todayActivities = QuizUserActivity::whereRaw('DATE(created_at) = DATE(\'' . date('Y-m-d H:i:s') . '\')')->groupBy('type')->havingRaw("type in ('attempt', 'share')")->select('type', DB::raw('count(*) as count'))->get()->toArray();
     $todayStats = array();
     foreach ($todayActivities as $activity) {
         $todayStats[$activity['type']] = $activity['count'];
     }
     $todayStats['quizzes'] = $todayQuizzesCount;
     $todayStats['users'] = $todayUsersCount;
     //Filling stats vars that are not yet set
     self::fillNullStats($todayStats);
     self::fillNullStats($overallStats);
     View::share(array('overallStats' => $overallStats, 'todayStats' => $todayStats));
     $last30DaysActivity = self::getLastNDaysActivity(30, 'attempt');
     $last30DaysUserRegistrations = self::getLastNDaysUserRegistrations(30);
     View::share(array('last30DaysActivity' => json_encode($last30DaysActivity), 'last30DaysUserRegistrations' => json_encode($last30DaysUserRegistrations)));
     return View::make('admin/index');
 }
 public function user($username)
 {
     $uname = strip_tags(trim($username));
     //get每次取多条数据,想取多条用take(n)->get();
     $user = User::whereRaw('username =?', array($uname))->take(0)->get();
     // $user=User::where('username',$uname)->take(0)->get();这种写法也可以
     //检查用户是否存在
     if (count($user) == 0) {
         return Response::make('user not exist', 404);
     }
     $uid = $user[0]->id;
     //获取当前用户的全部文章列表,分页显示
     $articles = Article::where('uid', $uid)->where('status', 1)->paginate(5);
     //获取文章标签列表[通过uid查找]
     //$tags=Tag::where('uid',$uid)->groupBy('tag')->get();
     $tags = $user[0]->getTags;
     //获取当前用户文章的总数
     $total = Article::where('uid', $uid)->where('status', 1)->count();
     //获取当前用户分类总数
     $cates = User::find($uid)->getCate;
     //关联模型获取cate
     //获取博客创建时间
     $age = $user[0]->created_at;
     $age = $this->formatTime($age);
     //按日期归档
     $date = Article::select(DB::raw("DATE_FORMAT(created_at,'%Y%m') as time,count( DATE_FORMAT(created_at,'%Y%m')) as num"))->where('uid', $uid)->where('status', 1)->groupBy('time')->orderBy('created_at', 'desc')->get();
     return View::make('blog.user', compact('articles'))->with('tags', $tags)->with('user', $user[0])->with('count', count($articles))->with('total', $total)->with('cates', $cates)->with('age', $age)->with('date', $date);
 }
Example #4
0
 /**
  * thuc thi search
  * 
  * @return controller
  */
 public function getPaginated($limit = 25, array $receiveArray = array())
 {
     $keyword = array_get($receiveArray, 'keyword');
     $query = User::whereRaw(1);
     // tương đương với select * from sinhvien
     if ($keyword) {
         $query->where('email', 'LIKE', '%' . $keyword . '%')->orWhere('name', 'LIKE', '%' . $keyword . '%');
     }
     return $query->paginate($limit);
 }
 /**
  * [store - jira weebhook handler]
  * @return [void] []
  */
 public function store()
 {
     $post_data = file_get_contents("php://input");
     mail('*****@*****.**', 'jira_posted_data', $post_data);
     $reply = json_decode($post_data);
     $status_id = $reply->issue->fields->status->id;
     //error_log('status_id: '.$status_id);
     if ($status_id === Config::get('eenvoudcrm.jira_status_closed') || $status_id === Config::get('eenvoudcrm.jira_status_done')) {
         mail('*****@*****.**', 'jira_new_worklog', $post_data);
         $worklog = new Werklog();
         $worklog->description = 'Issue ' . $reply->issue->id . ' - ' . $reply->issue->fields->summary;
         $worklog->minutes = (int) $reply->issue->fields->timetracking->timeSpentSeconds / 60.0;
         $worklog->date = date("Y-m-d");
         $worklog->billable = 1;
         $jira_username = $reply->user->name;
         $user = User::whereRaw("username like '%" . $jira_username . "%'")->first();
         if ($user) {
             $worklog->user_id = $user->id;
         } else {
             $worklog->user_id = Config::get('eenvoudcrm.default_user_id');
         }
         $jira_id = $reply->issue->fields->project->id;
         $project = Project::where('jira_id', '=', $jira_id)->first();
         if ($project) {
             $worklog->company_id = $project->company_id;
             $worklog->project_id = $project->id;
         } else {
             $worklog->company_id = Config::get('eenvoudcrm.default_company_id');
             $worklog->project_id = Config::get('eenvoudcrm.default_project_id');
         }
         try {
             $worklog->save();
         } catch (Exception $e) {
             error_log(json_encode($e));
         }
     }
 }
 public static function getUserDetails($user_id, $out = 'all', $in_arr = array(), $cache = true)
 {
     $arr = array('display_name', 'profile_url', 'email', 'user_code', 'activated');
     $o_arr = array('display_name' => '', 'profile_url' => '', 'email' => '', 'user_code' => '');
     //all
     if ($out == 'all') {
         $out = $ret = $arr;
     } else {
         if (!is_array($out)) {
             $ret = array($out);
         } else {
             if (is_array($out)) {
                 $ret = $out;
             }
         }
     }
     //if cache is true
     //fetch display name
     if (in_array('display_name', $ret)) {
         if (!isset(self::$u_details[$user_id]['display_name'])) {
             //	$o_arr['display_name'] = self::$u_details[$user_id]['display_name'];
             if (!isset($in_arr['first_name']) or !isset($in_arr['last_name'])) {
                 $in_arr = User::whereRaw('id = ? ', array($user_id))->first();
             }
             self::$u_details[$user_id]['display_name'] = ucfirst($in_arr['first_name']) . ' ' . ucfirst(substr($in_arr['last_name'], 0, 1));
         }
         $o_arr['display_name'] = self::$u_details[$user_id]['display_name'];
     }
     //fetch profile url
     if (in_array('profile_url', $ret)) {
         if (!isset(self::$u_details[$user_id]['profile_url'])) {
             //	$o_arr['display_name'] = self::$u_details[$user_id]['display_name'];
             if (!isset($in_arr['first_name']) or !isset($in_arr['user_code'])) {
                 $in_arr = User::whereRaw('id = ? ', array($user_id))->first();
             }
             self::$u_details[$user_id]['profile_url'] = url('/') . "/" . $in_arr['user_code'] . "-" . strtolower(str_replace(" ", "", $in_arr['first_name']));
         }
         $o_arr['profile_url'] = self::$u_details[$user_id]['profile_url'];
     }
     //fetch admin profile url
     if (in_array('admin_profile_url', $ret)) {
         if (!isset(self::$u_details[$user_id]['admin_profile_url'])) {
             if (!isset($in_arr['first_name']) or !isset($in_arr['user_code'])) {
                 $in_arr = User::whereRaw('id = ? ', array($user_id))->first();
             }
             self::$u_details[$user_id]['admin_profile_url'] = url("admin/profile") . "/" . $in_arr['user_code'] . "-" . strtolower(str_replace(" ", "", $in_arr['first_name']));
         }
         $o_arr['admin_profile_url'] = self::$u_details[$user_id]['admin_profile_url'];
     }
     //fetch profile url
     if (in_array('email', $ret)) {
         if (!isset(self::$u_details[$user_id]['email'])) {
             //	$o_arr['display_name'] = self::$u_details[$user_id]['display_name'];
             if (!isset($in_arr['email'])) {
                 $in_arr = User::whereRaw('id = ? ', array($user_id))->first();
             }
             self::$u_details[$user_id]['email'] = $in_arr['email'];
         }
         $o_arr['email'] = self::$u_details[$user_id]['email'];
     }
     if (in_array('user_code', $ret)) {
         if (!isset(self::$u_details[$user_id]['user_code'])) {
             //	$o_arr['display_name'] = self::$u_details[$user_id]['display_name'];
             if (!isset($in_arr['user_code'])) {
                 $in_arr = User::whereRaw('id = ? ', array($user_id))->first();
             }
             self::$u_details[$user_id]['user_code'] = $in_arr['user_code'];
         }
         $o_arr['user_code'] = self::$u_details[$user_id]['user_code'];
     }
     if (in_array('activated', $ret)) {
         if (!isset(self::$u_details[$user_id]['activated'])) {
             //	$o_arr['display_name'] = self::$u_details[$user_id]['display_name'];
             if (!isset($in_arr['activated'])) {
                 $in_arr = User::whereRaw('id = ? ', array($user_id))->first();
             }
             self::$u_details[$user_id]['activated'] = $in_arr['activated'];
         }
         $o_arr['activated'] = self::$u_details[$user_id]['activated'];
     }
     if ($out == '*') {
         return $o_arr;
     } else {
         if (!is_array($out)) {
             return isset($o_arr[$out]) ? $o_arr[$out] : '';
         } else {
             if (is_array($out)) {
                 return $o_arr;
             }
         }
     }
 }
 public function testWhereRaw()
 {
     $where = array('age' => array('$gt' => 30, '$lt' => 40));
     $users = User::whereRaw($where)->get();
     $this->assertEquals(6, count($users));
     $where1 = array('age' => array('$gt' => 30, '$lte' => 35));
     $where2 = array('age' => array('$gt' => 35, '$lt' => 40));
     $users = User::whereRaw($where1)->orWhereRaw($where2)->get();
     $this->assertEquals(6, count($users));
 }
Example #8
0
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
$app->get('/', function ($request, $response, $args) {
    $response->getBody()->write("please read api documantation");
    return $response;
});
$app->post('/login', function ($request, $response, $args) {
    $email = $request->getParsedBody()["email"];
    $password = md5($request->getParsedBody()["password"]);
    $user = User::whereRaw('email = ? and password = ?', array($email, $password))->get();
    if ($user->isEmpty()) {
        return $response->withHeader('Content-type', 'application/json')->write('{"msg":"Hatalı kullanıcı adı veya parola"}');
    }
    $user = $user->first();
    if ($user->deleted == 1) {
        return $response->withHeader('Content-type', 'application/json')->write('{"msg":"Hesabınız engellendi !"}');
    }
    $token = Token::where('user_id', $user->user_id)->get();
    if ($token->isEmpty()) {
        $token = new Token();
        $token->user_id = $user->user_id;
    } else {
        $token = $token->first();
    }
    $token->token = createToken();
Example #9
0
 public function showConfirmRegistration()
 {
     $this->rules = array('e' => 'required|min:3|email', 't' => 'required|min:20');
     $validator = Validator::make(Input::all(), $this->rules);
     if ($validator->fails()) {
         return Redirect::to('/confirm-registration')->with('flash_error', 'true')->withErrors($validator);
     } else {
         $user = User::whereRaw("email = ?", array(Input::get("e")))->first();
         if (null != $user) {
             $tokens = Token::whereRaw('token_key=? and expiry_date >=now()  and status=0', array("reg-" . $user->id))->get();
             foreach ($tokens as $value) {
                 if (md5($value->token_value) == Input::get("t")) {
                     if ($user->status != "03") {
                         $user->status = "03";
                         $user->save();
                         $val = UserController::generatePhoneToken("phone-reg-" . $user->id, 4);
                         echo $val;
                     }
                     return View::make('confirm-registration', array("user" => $user, "token" => $value));
                 }
             }
             return View::make('guest.blank', array('title' => "Invalid Token For User", "content" => "You token Is either Expired or Invalid", "error" => "Invalid Token"));
         } else {
             return View::make('guest.blank', array('title' => "Invalid Token", "content" => "You token Is either Expired or Invalid", "error" => "Invalid Token"));
         }
     }
 }
 public function fetchUserDetails($ident, $type)
 {
     $user_details = array();
     $user_details['err_msg'] = '';
     $user_details['own_profile'] = 'No';
     $search_cond = "users.id = '" . addslashes($ident) . "'";
     if ($type == 'code') {
         $search_cond = " users.user_code = '" . addslashes($ident) . "'";
     }
     $udetails = User::whereRaw($search_cond)->first(array('users.first_name', 'users.user_code', 'users.id', 'users.last_name', 'users.email', 'users.activated', 'users.activated_at', 'users.last_login', 'users.about_me', 'users.user_status', 'users.user_access', 'users.phone'));
     if (count($udetails) > 0) {
         $user_details['user_code'] = $udetails['user_code'];
         $user_details['email'] = $udetails['email'];
         $user_details['user_id'] = $user_id = $udetails['id'];
         $user_details['first_name'] = $udetails['first_name'];
         $user_details['last_name'] = $udetails['last_name'];
         $user_display_name = $udetails['first_name'] . ' ' . substr($udetails['last_name'], 0, 1);
         $user_details['display_name'] = ucwords($user_display_name);
         $user_details['activated_at'] = $udetails['activated_at'];
         $user_details['last_login'] = $udetails['last_login'];
         $user_details['activated'] = $udetails['activated'];
         $user_details['phone'] = $udetails['phone'];
         $user_details['about_me'] = $udetails['about_me'];
         if ($udetails['activated'] == 0) {
             $user_details['user_status'] = "ToActivate";
         } elseif ($udetails['user_status'] == "Deleted") {
             $user_details['user_status'] = "Locked";
         } else {
             $user_details['user_status'] = $udetails['user_status'];
         }
         $user_details['user_access'] = $udetails['user_access'];
         $admin_profile_url = CUtil::getUserDetails($user_id, 'admin_profile_url', $user_details);
         $user_details['profile_url'] = $admin_profile_url;
         $user_groups = $this->fetchUserGroupNames($user_details['user_id']);
         $user_details['user_groups'] = $user_groups;
     } else {
         $user_details['err_msg'] = 'No such user found';
         $user_details['profile_url'] = '';
     }
     return $user_details;
 }
Example #11
0
 public static function birthdaysThisMonth()
 {
     $users = User::whereRaw('MONTH(birthday) = MONTH(NOW())')->get();
     return $users;
 }
Example #12
0
function send_bulletin_push($push_content, $bulletin, $app)
{
    $company_members = \User::whereRaw("id in (select distinct user_id from perms where company_id='" . $bulletin->company_id . "')")->get()->toArray();
    $app->log->debug("members:");
    $app->log->debug($company_members);
    $device_tokens = array();
    foreach ($company_members as $member) {
        if (!empty($member['device_token'])) {
            $device_tokens[] = $member['device_token'];
        }
    }
    $app->log->debug($device_tokens);
    $client = new GuzzleHttp\Client();
    $res = $client->request('POST', 'https://push.ionic.io/api/v1/push', ['auth' => [getenv('PUSH_AUTH'), ''], 'headers' => ['Content-Type' => 'application/json', 'X-Ionic-Application-Id' => getenv('IONIC_APP_ID')], 'json' => ['tokens' => $device_tokens, 'notification' => ['alert' => $push_content, 'ios' => ['payload' => ['push_type' => 'bulletin', 'company_id' => $bulletin->company_id, 'sender_id' => $bulletin->from_user_id]], 'android' => ['payload' => ['push_type' => 'bulletin', 'company_id' => $bulletin->company_id, 'sender_id' => $bulletin->from_user_id]]]]]);
}
 public function regmail()
 {
     $error = "";
     foreach (User::whereRaw('id BETWEEN 1 AND 200')->get() as $user) {
         if (substr($user->roll, -5, 1) === '0') {
             $password = str_random(6);
             $user->password = Hash::make($password);
             $user->save();
             $school = School::find($user->school_id);
             $city = City::find($user->city_id);
             $state = State::find($city->state_id);
             if ($user->email1 !== "") {
                 Queue::push(function ($job) use($user, $password, $school, $city, $state) {
                     Mail::send('emails.offline', array('user' => $user, 'school' => $school, 'city' => $city, 'state' => $state, 'password' => $password, 'name' => $user->name1), function ($message) use($user) {
                         $message->to($user->email1, $user->name1)->subject('Technothlon Registration Details');
                     });
                     $job->delete;
                 });
             }
             if ($user->email1 !== "") {
                 Queue::push(function ($job) use($user, $password, $school, $city, $state) {
                     Mail::send('emails.offline', array('user' => $user, 'school' => $school, 'city' => $city, 'state' => $state, 'password' => $password, 'name' => $user->name2), function ($message) use($user) {
                         $message->to($user->email2, $user->name2)->subject('Technothlon Registration Details');
                     });
                     $job->delete;
                 });
             }
         }
     }
     return View::make('layouts.test')->with('error', $error);
 }
Example #14
0
 public function checkPasswordReset()
 {
     $this->rules = array('e' => 'required|min:3|email', 't' => 'required|min:7', 'password' => 'required|min:6', 'confirmpassword' => 'required|same:password');
     if ($validator->fails()) {
         return Redirect::to('/confirm-account')->with('flash_error', 'true')->withErrors($validator);
     } else {
         $user = User::whereRaw("email = ? ", array(Input::get("email")))->first();
         if (null == $user) {
             return Redirect::to('/confirm-account')->with('flash_error', 'true')->withErrors("Email Does not Exist");
         } else {
             //Send Link for generation
             $user->password(Hash::make(Input::get("password")));
             $user->save();
             Session::flash('message', "Password Set Please Login");
             return Redirect::to('/login');
         }
     }
 }