예제 #1
0
 public function actionLogon()
 {
     $result = array('status' => -1, 'access_token' => -1, 'userid' => 0, 'message' => '');
     $paras = Yii::$app->request->post();
     //$query->
     if (!isset($paras['password'], $paras['name'], $paras['email'], $paras['firstname'], $paras['lastname'], $paras['sex'], $paras['phone'], $paras['code'])) {
         $result['message'] = 'lack of parameters';
         return $result;
     }
     if (!$this->checkInvitation($paras['code'])) {
         $result['message'] = 'wrong invitation code';
         $result['status'] = '2';
         return $result;
     }
     $user = new \app\models\User();
     $user->password = md5($paras['password'], false);
     $user->name = $paras['name'];
     $user->email = $paras['email'];
     $user->firstname = $paras['firstname'];
     $user->lastname = $paras['lastname'];
     $user->sex = $paras['sex'];
     $user->phone = $paras['phone'];
     $user->access_token = $user->password;
     if ($user->validate()) {
         $user->save();
         $result['access_token'] = $user->access_token;
         $result['status'] = 1;
         $result['userid'] = $user->id;
         $result['message'] = 'registered succesfully';
     } else {
         $result['message'] = 'registered failed';
         $result['status'] = 0;
     }
     return $result;
 }
 public function up()
 {
     $user = new app\models\User();
     $user->email = 'admin';
     $user->password = '******';
     $user->save();
 }
예제 #3
0
 public function actionSignUp()
 {
     $model = new \app\models\User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect('/personal');
     }
     return $this->render('sign-up', ['model' => $model]);
 }
예제 #4
0
 public function up()
 {
     $result = $this->createTable('{{%users}}', ['id' => Schema::TYPE_PK, 'username' => Schema::TYPE_STRING . ' NOT NULL COMMENT "Логин"', 'email' => Schema::TYPE_STRING . ' NOT NULL COMMENT "Email"', 'password' => Schema::TYPE_STRING . ' NOT NULL COMMENT "Пароль"', 'authKey' => Schema::TYPE_STRING . ' NOT NULL COMMENT "Токен"']);
     foreach ($this->_data as $item) {
         $model = new \app\models\User();
         $model->attributes = $item;
         $model->save();
     }
     return $result;
 }
예제 #5
0
 public function store(Request $request, Response $response, Hash $hash)
 {
     $rules = ['email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:8'];
     $validator = app('validation')->make($request->all(), $rules);
     if ($validator->fails()) {
         $request->session->add(['errors' => $validator->errors()->all()]);
         return app('twig')->render('user/signup.htm', ['oldInputs' => $request->all()]);
     }
     $user = new \app\models\User();
     $user->email = $request->body->get('email');
     $user->password = $hash->make($request->body->get('password'));
     $user->save();
     $request->session->add(['success' => "Welcome to Notejam, you can now log in."]);
     return $response->redirect('/signin');
 }
예제 #6
0
 public function login()
 {
     $proffstore = new ProffstoreCURL();
     $proffstore->auth($this->password, $this->email);
     if ($proffstore->accesToken) {
         $user = \app\models\User::findOne(['email' => $this->email]);
         if ($user) {
             $user->setAttribute('tocken', $proffstore->accesToken);
             $user->update(false);
         } else {
             $user = new \app\models\User();
             $user->setAttributes(['email' => $this->email, 'pass' => $this->password, 'tocken' => $proffstore->accesToken]);
             $user->setAttribute('tocken', $proffstore->accesToken);
             $user->save(false);
         }
         \Yii::$app->user->login($user, 3600 * 24 * 3);
         return $proffstore->accesToken;
     } else {
         return null;
     }
 }
예제 #7
0
 /**
  * Ruturn user-setup page if application no-user found.
  * @return mixed
  */
 public function actionUserSetup()
 {
     $chkUserTbl = \app\models\User::find()->exists();
     if ($chkUserTbl) {
         return $this->redirect(['setup-completed']);
     }
     $model = new \app\models\User();
     $model->scenario = 'firstTime';
     $chkUserTbl = \app\models\User::find()->exists();
     if ($chkUserTbl) {
         return $this->redirect(['site/login']);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->created_by = 1;
         $model->created_at = new \yii\db\Expression('NOW()');
         $model->user_login_id = $model->admin_user;
         $model->user_password = MD5($model->create_password . $model->create_password);
         $model->user_type = 'A';
         if ($model->save()) {
             $auth_assign = new \app\models\AuthAssignment();
             $auth_assign->item_name = 'SuperAdmin';
             $auth_assign->user_id = $model->user_id;
             $auth_assign->created_at = date_format(date_create(), 'U');
             if ($auth_assign->save(false)) {
                 return $this->redirect(['setup-completed']);
             }
         }
     }
     return $this->render('user-setup', ['model' => $model]);
 }
예제 #8
0
    $app->config(array('log.enable' => true, 'log.level' => \Slim\Log::ERROR, 'debug' => false));
});
// Only invoked if mode is "development"
$app->configureMode('development', function () use($app) {
    $app->config(array('log.enable' => true, 'log.level' => \Slim\Log::DEBUG, 'debug' => true));
});
$app->group('/gateway', function () use($app) {
    $app->post('/register', function () use($app) {
        $json = $app->request->getBody();
        $data = json_decode($json, false);
        // TODO: Send email for confirmation
        $pass = \app\utilities\PasswordUtility::GenerateSalt();
        $now = date("Y-m-d H:i:s");
        $hash = password_hash($data->Email . $now, PASSWORD_DEFAULT);
        $user = new \app\models\User(array('username' => $data->Email, 'password' => password_hash($pass, PASSWORD_DEFAULT), 'email' => $data->Email, 'confirmation' => $now));
        $user->save();
        $apiId = \app\utilities\PasswordUtility::GenerateSalt();
        $apiKey = \app\utilities\PasswordUtility::GenerateSalt();
        $userAuthorization = new \app\models\UserAuthorization(array('user_id' => $user->id, 'api_id' => $apiId, 'api_key' => password_hash($apiKey, PASSWORD_DEFAULT)));
        $userAuthorization->save();
        echo json_encode(array('ResponseCode' => \config\Constants::$success, 'APIId' => $apiId, 'APIKey' => $apiKey));
    });
});
// API group
$app->group('/api', function () use($app) {
    $app->get('/turbulencedata/:latitude/:longitude(/:radius(/:hoursUntilStale))', function ($latitude, $longitude, $radius = 1, $hoursUntilStale = 2) {
        $controller = new \app\controllers\TurbulenceStatisticController();
        $finalResults = $controller->getTurbulenceData($latitude, $longitude, $radius, $hoursUntilStale);
        echo json_encode(array('ResponseCode' => \config\Constants::$success, 'Results' => $finalResults));
    });
    $app->post('/turbulencestatistic', function () use($app) {