Ejemplo n.º 1
0
 public function actionLogin()
 {
     if (yii::$app->request->isPost) {
         $data = yii::$app->request->post();
         $model = new Users();
         $user = $model->findOne(['username' => $data['login']]);
         if (password_verify($data["password"], $user->password)) {
             $login = yii::$app->user->login($user);
             if ($login) {
                 $this->redirect(['/index/index']);
             }
         } else {
             return $this->render('index', $data);
         }
     }
 }
Ejemplo n.º 2
0
 public function createUser($request)
 {
     $validation = Validator::make($request->all(), ['name' => 'required', 'email' => 'required|unique:users,email', 'password' => 'required|min:6']);
     if ($validation->passes()) {
         Users::create(array('name' => $request->input('name'), 'email' => $request->input('email'), 'password' => bcrypt($request->input('password'))));
         return array('status' => 1);
     } else {
         $validation = $validation->messages();
         return array('msg' => $validation, 'status' => 0);
     }
 }
 public function messageSent($request)
 {
     $this->userInfo = $request;
     $message_information = [];
     $message_information['message_from'] = session('active_user_id');
     $message_information['message_to'] = Users::where('email', '=', $this->userInfo->userInfo->input('message_to'))->pluck('id');
     $message_information['message'] = $this->userInfo->userInfo->input('message');
     DB::beginTransaction();
     Message::create($message_information);
     Notification::create(array('msg_from_user_id' => session('active_user_id')));
     DB::commit();
 }
Ejemplo n.º 4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $active_user = Users::where('email', $request->input('email'))->where('status', '=', 1)->first();
     if (Hash::check($request->input('password'), $active_user['password'])) {
         Session::put('user_active', 1);
         Session::put('active_user_id', $active_user['id']);
     }
     if (session('user_active') == 1) {
         return $next($request);
     } else {
         return view('registration/login')->with(array('msg' => 'Wrong Credentials or User  inactive'));
     }
 }
 public function actionAdd()
 {
     $model = new Users();
     $id = !empty(yii::$app->request->get('id')) ? yii::$app->request->get('id') : 0;
     $item = $model::find()->where(['id' => $id])->asArray()->one();
     if ($item) {
         $this->headerPage = "Редактировать пользователя - " . $item["username"];
     } else {
         $this->headerPage = "Добавить пользователя";
     }
     if (yii::$app->request->isPost) {
         $pathInfo = Yii::$app->request->pathInfo;
         $fields = Yii::$app->request->post();
         if (isset($fields["main"]["id"])) {
             $id = $fields["main"]["id"];
         } else {
             $id = Yii::$app->request->get('id') ? (int) Yii::$app->request->get('id') : 0;
         }
         foreach ($fields["main"] as $index => $value) {
             $model->{$index} = $value;
         }
         $model->attributes = $fields["main"];
         if (!empty(Yii::$app->request->get('id'))) {
             $model->password = "******";
         }
         if ($model->validate()) {
             $data = $model->MakeData($fields["main"]);
             $insert_id = $model->Add($id, $data);
             $this->redirect(Url::to(["/{$pathInfo}", "id" => $insert_id]));
         } else {
             $errors = $model->errors;
             app::PrintPre($errors);
         }
     }
     $interface = $this->MakeInterface($item);
     return $this->render('add', ['interface' => $interface, 'data' => $item]);
 }
Ejemplo n.º 6
0
 public function getProfileUpdate(Request $request)
 {
     $messages = Users::find($request->input('user_id'))->message->count();
     $allMessages = Users::find($request->input('user_id'))->message->lists('message');
     $notifications = Users::find($request->input('user_id'))->notification->count();
     return array('messages' => $messages, 'notifications' => $notifications, 'messageList' => $allMessages);
 }