public function run()
 {
     DB::table('acl_user_member')->truncate();
     DB::table('acl_users')->truncate();
     $users = array(array('username' => 'raphael.torres', 'fullname' => 'Raphael Torres', 'email' => 'raphael@aligncommerce.com', 'password' => Hash::make('password123'), 'company_name' => 'Align Commerce', 'last_login' => new DateTime(), 'last_login_ip' => '127.0.0.1', 'confirmed' => 1, 'confirmation_code' => md5(microtime() . Config::get('app.key')), 'return_url' => 'http://api.aligncommerce.com/', 'last_password_change' => new DateTime(date('Y-m-d H:i:s', strtotime("+30 days"))), 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('username' => 'pinky.torres', 'fullname' => 'Pinky L Torres', 'email' => 'user@example.org', 'password' => Hash::make('password123'), 'company_name' => 'Align Commerce', 'last_login' => new DateTime(), 'last_login_ip' => '127.0.0.1', 'confirmed' => 1, 'confirmation_code' => md5(microtime() . Config::get('app.key')), 'return_url' => 'http://api.aligncommerce.com/', 'last_password_change' => new DateTime(date('Y-m-d H:i:s', strtotime("+30 days"))), 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('username' => 'michael.liwanagan', 'fullname' => 'Michael Liwanagan', 'email' => 'michael.liwanagan@gmail.com', 'password' => Hash::make('michael123'), 'company_name' => 'Align Commerce', 'last_login' => new DateTime(), 'last_login_ip' => '127.0.0.1', 'confirmed' => 1, 'confirmation_code' => md5(microtime() . Config::get('app.key')), 'return_url' => 'http://api.aligncommerce.com/', 'last_password_change' => new DateTime(date('Y-m-d H:i:s', strtotime("+30 days"))), 'created_at' => new DateTime(), 'updated_at' => new DateTime()));
     DB::table('acl_users')->insert($users);
     foreach (range(1, 2) as $index) {
         $usermember = new UserMember();
         $usermember->user_id = $index;
         $usermember->group_id = $index;
         $usermember->save();
     }
 }
 public function player()
 {
     if (ACL::checkUserPermission('points.player') == false) {
         return Redirect::action('dashboard');
     }
     $form_open = Form::open(array('method' => 'post', 'files' => true, 'id' => 'form-player-csv', 'class' => 'smart-form', 'role' => 'form'));
     $userList = UserMember::with('user', 'group', 'points')->where('group_id', 4)->get();
     $title = Lang::get('Player List');
     $client_ip = Request::getClientIp(true);
     $data = array('acl' => ACL::buildACL(), 'userList' => $userList, 'title' => $title, 'form_open' => $form_open, 'client_ip' => $client_ip);
     return View::make('points/index', $data);
 }
Example #3
0
 /**
  * 用户忘记密码后使用手机号获得验证码重置密码
  * @param $mobile
  * @param $password
  * @param $checkNum
  * @return array|int
  */
 public function resetPassword($mobile, $password, $checkNum)
 {
     //        $passwordMd5 = md5($password);
     $data = array();
     try {
         $userId = self::getUserByMobile($mobile);
         if (!$userId) {
             return 10006;
             //  MSG_ERR_UN_REGISTER_MOBILE
         }
         $mobile_checkcode = LogMobileCheckcode::model()->checkCode($mobile, $checkNum);
         if (!$mobile_checkcode) {
             return 10005;
             //  MSG_ERR_CODE_OVER_TIME
         }
         //手机号码已注册且验证码正确  update
         Yii::app()->cnhutong_user->createCommand()->update('user', array('password' => $password), 'mobile = :mobile', array(':mobile' => $mobile));
         //修改成功,验证码使用后改变验证码status状态
         Yii::app()->cnhutong_user->createCommand()->update('log_mobile_checkcode', array('status' => 1), 'mobile = :mobile', array(':mobile' => $mobile));
         //userId
         $data['userId'] = $userId;
         //token
         $data['token'] = UserToken::model()->getToken($userId);
         //用户昵称,积分,等级
         $userMessage = self::getUserMessageByUserId($userId);
         $data['mobile'] = $userMessage['mobile'];
         $data['nickname'] = $userMessage['username'];
         $data['points'] = $userMessage['score'];
         $data['level'] = $userMessage['level'];
         //members
         $data['members'] = UserMember::model()->getMembers($userId);
         if (!$data['members']) {
             $data['members'] = [];
         }
     } catch (Exception $e) {
         error_log($e);
     }
     return $data;
 }
Example #4
0
 public function isPlayer()
 {
     $isPlayer = UserMember::with('group')->where('user_id', Auth::user()->id)->get();
     foreach ($isPlayer as $group) {
         if (strpos(strtolower($group->group->name), 'player') !== false) {
             return true;
         }
     }
     return false;
 }
 /**
  * action_id : 2110
  * 用户解除绑定学员信息      actionRemoveMember()
  * @memberId $memberId string       --绑定学员对应ID
  * @token  $token  string       --登录token
  * @userId  $userId int         --用户id(APP中用户的唯一标识)
  * @return result          调用返回结果
  * @return msg             调用返回结果说明
  * @return data             调用返回数据
  */
 public function actionRemoveMember()
 {
     if (!isset($_REQUEST['userId']) || !isset($_REQUEST['token']) || !isset($_REQUEST['memberId'])) {
         $this->_return('MSG_ERR_LESS_PARAM');
     }
     $userId = Yii::app()->request->getParam('userId', NULL);
     $token = Yii::app()->request->getParam('token', NULL);
     $memberId = Yii::app()->request->getParam('memberId', NULL);
     // 解除绑定学员id
     $data = UserMember::model()->removeMember($userId, $token, $memberId);
     if ($data === 20008) {
         $this->_return('MSG_ERR_FAIL_USER');
     } elseif ($data === 20007) {
         $this->_return('MSG_ERR_FAIL_TOKEN');
     } elseif ($data === 20017) {
         $this->_return('MSG_ERR_FAIL_MEMBER');
     }
     // TODO : add log
     $actionId = 2110;
     $params = '';
     foreach ($_REQUEST as $key => $value) {
         $params .= $key . '=' . $value . '&';
     }
     LogUserAction::model()->userAction($userId, $actionId, $params);
     $this->_return('MSG_SUCCESS', $data);
 }
 public function upload()
 {
     if (Input::hasFile('playerfile')) {
         $file = Input::file('playerfile');
         $up = Excel::load($file, function ($reader) {
             $results = $reader->get()->toArray();
             foreach ($results as $row) {
                 $player_group_id = Group::where('name', 'Player')->firstOrFail();
                 $days = new DateTime(date('Y-m-d H:i:s', strtotime("+30 days")));
                 $player_account = array('email' => '', 'password' => Hash::make(''), 'confirmed' => 1, 'status' => 1, 'password_expiration_date' => $days, 'account_expiration_date' => $days, 'created_at' => new DateTime(), 'updated_at' => new DateTime());
                 foreach ($row as $key => $value) {
                     $player_account[$key] = $value;
                 }
                 try {
                     $add_account = User::create($player_account);
                     $user_member = array('user_id' => $add_account->id, 'group_id' => $player_group_id->id, 'date_created' => new DateTime());
                     $add_member = UserMember::create($user_member);
                     $player_points = array('account_id' => $add_account->id);
                     $add_points = Points::create($player_points);
                 } catch (Exception $e) {
                     // return false;
                 }
             }
         });
         if ($up) {
             $messages = 'Upload Successful.';
             $status = 'success';
         } else {
             $messages = 'Upload failed.';
             $status = 'error';
         }
         return Redirect::route('player.index')->with($status, $messages);
     } else {
         return Redirect::action('player.index')->with('error', 'Please select a Excel or CSV File.');
     }
 }
 /**
  * 用户解除绑定学员信息      actionRemoveMember()
  * @salt $memberId string       --绑定学员对应ID
  * @token  $token  string       --登录token
  * @userId  $userId int         --用户id(APP中用户的唯一标识)
  * @return result          调用返回结果
  * @return msg             调用返回结果说明
  * @return data             调用返回数据
  */
 public function actionRemoveMember()
 {
     if (!isset($_REQUEST['userId']) || !isset($_REQUEST['token']) || !isset($_REQUEST['memberId'])) {
         $this->_return('MSG_ERR_LESS_PARAM');
     }
     $userId = Yii::app()->request->getParam('userId', NULL);
     $token = Yii::app()->request->getParam('token', NULL);
     $memberId = Yii::app()->request->getParam('memberId', NULL);
     $version = Yii::app()->request->getParam('version', NULL);
     $deviceId = Yii::app()->request->getParam('deviceId', NULL);
     $platform = Yii::app()->request->getParam('platform', NULL);
     $channel = Yii::app()->request->getParam('channel', NULL);
     $appVersion = Yii::app()->request->getParam('appVersion', NULL);
     $osVersion = Yii::app()->request->getParam('osVersion', NULL);
     $appId = Yii::app()->request->getParam('appId', NULL);
     // 解除绑定学员id
     $data = UserMember::model()->removeMember($userId, $token, $memberId);
     if ($data === 10009) {
         $this->_return('MSG_ERR_FAIL_TOKEN');
     } elseif ($data === 10010) {
         $this->_return('MSG_ERR_FAIL_USER');
     } elseif ($data === 40003) {
         $this->_return('MSG_ERR_FAIL_MEMBER');
     }
     //记录log
     $this->_return('MSG_SUCCESS', $data);
 }
Example #8
0
 /**
  * Add and Edit user member
  */
 public static function userMemberAddEdit($userId, $data = array())
 {
     UserMember::where('user_id', '=', $userId)->delete();
     foreach ($data as $val) {
         $user_member = new UserMember();
         $user_member->user_id = $userId;
         $user_member->group_id = $val;
         $user_member->date_created = new DateTime();
         $user_member->save();
     }
 }
 /**
  * 学员对上过的课时进行评价和打分
  * @param $userId                   -- 用户ID
  * @param $token                    -- 用户验证token
  * @param $memberId                 -- 用户当前绑定的学员对对应的ID
  * @param $lessonStudentId          -- 课时唯一编号
  * @param $score                    -- 学员给课时的评分,1-5分
  * @param $stateComment             -- 课时评价,可以为空
  * @return array|int
  */
 public function lessonStudent($userId, $token, $memberId, $lessonStudentId, $score, $stateComment)
 {
     $data = array();
     try {
         // 用户ID验证
         $user = User::model()->IsUserId($userId);
         if (!$user) {
             return 10010;
             // MSG_ERR_FAIL_USER
         }
         // 用户token验证
         $userToken = UserToken::model()->IsToken($userId, $token);
         //            var_dump($userToken);exit;
         if (!$userToken) {
             return 10009;
             // MSG_ERR_FAIL_TOKEN
         }
         $isExistUserMemberId = UserMember::model()->IsExistMemberId($userId, $memberId);
         if (!$isExistUserMemberId) {
             return 40003;
             // MSG_ERR_FAIL_MEMBER
         }
         $isLessonStudentId = self::IsLessonStudentId($memberId, $lessonStudentId);
         if (!$isLessonStudentId) {
             return 60002;
         }
         if ($score < 0 || $score > 5) {
             return 70001;
         }
         $result = Yii::app()->cnhutong->createCommand()->update('ht_lesson_student', array('student_rating' => $score, 'student_comment' => $stateComment), 'student_id = :studentId And id = :id', array(':studentId' => $memberId, ':id' => $lessonStudentId));
         if (empty($result)) {
             $data[] = [];
         }
         //            $data = $result;
     } catch (Exception $e) {
         error_log($e);
     }
     return $data;
 }
 /**
  * 学员在APP中对自己的课时进行请假或者取消请假的操作
  * @param $userId
  * @param $token
  * @param $memberId
  * @param $lessonStudentId
  * @param $leaveType
  * @return array|int
  */
 public function lessonStudentLeave($userId, $token, $memberId, $lessonStudentId, $leaveType)
 {
     $nowTime = date("Y-m-d H-i-s");
     $data = array();
     try {
         // 用户ID验证
         $user = User::model()->IsUserId($userId);
         if (!$user) {
             return 20008;
             // MSG_ERR_FAIL_USER
         }
         // 用户token验证
         $userToken = UserToken::model()->IsToken($userId, $token);
         //            var_dump($userToken);exit;
         if (!$userToken) {
             return 20007;
             // MSG_ERR_FAIL_TOKEN
         }
         $isExistUserMemberId = UserMember::model()->IsExistMemberId($userId, $memberId);
         if (!$isExistUserMemberId) {
             return 20017;
             // MSG_ERR_FAIL_MEMBER
         }
         $isLessonStudentId = self::IsLessonStudentId($memberId, $lessonStudentId);
         if (!$isLessonStudentId) {
             return 20021;
             // MSG_ERR_LESSON_STUDENT_ID
         }
         // step 状态  0 - 等待确认,1 - 取消请假,3 - 锁定,2 - 请假完成
         $aStep = array(0, 1, 2, 3);
         // 学员请假
         if ($leaveType == 1) {
             $reminder = self::getHtReminder($memberId, $lessonStudentId);
             // 测试memberId = 410, lessonStudentId = 82
             if ($reminder) {
                 // 请假记录存在
                 $step = $reminder['step'];
                 if ($step == 1) {
                     // 学员请假后,客服未处理。学员又取消了请假,此时可以请假
                     self::setStep($memberId, $lessonStudentId, 0);
                     // 设置请假状态 为请假
                 } else {
                     return 20032;
                     //MSG_ERR_NO_LEAVE
                 }
             } else {
                 // 请假记录不存在
                 self::insertLeave($memberId, $lessonStudentId);
                 // 增加请假记录
             }
             //                var_dump($reminder['step']);
         } elseif ($leaveType == 2) {
             $reminder = self::getHtReminder($memberId, $lessonStudentId);
             if (!$reminder) {
                 // 请假记录不存在,当然不能取消请假
                 return 20033;
                 // MSG_ERR_NO_CANCEL_LEAVE
             } else {
                 // 请假记录存在,且 step = 0 则可以取消请假
                 $step = $reminder['step'];
                 if ($step == 0) {
                     self::setStep($memberId, $lessonStudentId, 1);
                     // 设置请假状态 为取消请假
                 } else {
                     return 20033;
                     // MSG_ERR_NO_CANCEL_LEAVE
                 }
             }
             //                var_dump(7);
         } else {
             return 20031;
         }
     } catch (Exception $e) {
         error_log($e);
     }
     return $data;
 }
    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
        if (ACL::checkUserPermission('user.edit') == false) {
            return Redirect::action('dashboard');
        }
        $user = User::where('id', $id)->find($id);
        $input = Input::all();
        $user->username = Input::get('username');
        $user->fullname = Input::get('fullname');
        $user->email = Input::get('email');
        $user->company_name = Input::get('company');
        $user->confirmed = Input::get('confirm');
        if (Input::has('changepassword')) {
            if (User::checkUserPassword($id, Input::get('password')) == true) {
                $msgType = 'error';
                $message = 'Password has been used before by the user. <br /> 
				Change the user\'s password at least 5 times before using the password again.';
                return Redirect::action('user.edit')->with($msgType, $message);
            }
            $user->password = Hash::make(Input::get('changepassword'));
            $user->last_password_change = new DateTime();
            $passwords = json_decode($user->passwords, true);
            if (sizeof($passwords) == 0) {
                $temp = array();
                $temp[] = Hash::make(Input::get('password'));
                $user->passwords = json_encode($temp);
            } else {
                array_push($passwords, Hash::make(Input::get('password')));
                if (sizeof($passwords) > 5) {
                    array_shift($passwords);
                }
                $user->passwords = json_encode($passwords);
            }
        }
        $user->save();
        if (Input::has('usermember')) {
            $userMember = Input::get('usermember');
            UserPermissions::where('user_id', '=', $user->id)->delete();
            ACL::userMemberAddEdit($user->id, $userMember);
        } else {
            UserPermissions::where('user_id', '=', $user->id)->delete();
            UserMember::where('user_id', '=', $id)->delete();
        }
        $message = 'User has been modified';
        return Redirect::action('settings.user')->with('success', $message);
    }
        $user = Auth::user();
        $settingsExpiry = Settings::getSettingValue('password_expiry');
        $expirationDate = User::userPasswordExpiry($user->password_expiration_date, $settingsExpiry);
        if (strtotime($expirationDate) < strtotime($date)) {
            $msgType = 'warning';
            $message = 'Your password has been expired. Please change your password.';
            return Redirect::action('user.profile')->with($msgType, $message);
        }
    } else {
        $errorMsg = 'Please login using your credentials';
        return Redirect::action('login.index')->with('error', $errorMsg);
    }
});
Route::filter('check_merchant', function () {
    if (Auth::check()) {
        $userMember = UserMember::with('group')->where('user_id', Auth::user()->id)->get();
        if ($userMember->count() > 0) {
            $fetch = array_fetch($userMember->toArray(), 'group.name');
            if (in_array('Merchant', $fetch)) {
                $merchant_id = Auth::user()->id;
                $merchant = Merchant::find($merchant_id);
                $merchant_arr = array('merchant_id' => $merchant_id);
                Session::put('merchant', $merchant_arr);
            }
        }
    } else {
        $errorMsg = 'Please login using your credentials';
        return Redirect::action('login.index')->with('error', $errorMsg);
    }
});
/*