예제 #1
0
파일: auth.php 프로젝트: cruide/wasp
 public function signin($id, $password, $type = UserContact::TYPE_EMAIL)
 {
     if (!is_scalar($id)) {
         return false;
     }
     $auth = UserContact::where('type', '=', $type)->where('value', '=', $id)->first();
     if (empty($auth)) {
         return false;
     }
     $obj = User::where('id', '=', $auth->user_id)->where('password', '=', password_crypt($password))->with('session')->first();
     if (!empty($obj->id)) {
         $session = $obj->session;
         if (empty($session->id)) {
             $session = new UserSession();
         }
         $session->session_id = $this->session->id(true);
         $session->user_id = $obj->id;
         $session->ip_address = get_ip_address();
         $session->stamp = time();
         $session->save();
         $this->autorization = true;
         $this->user = $session->user;
         $smarty = new \Smarty();
         $smarty->assignGlobal('auth_user', $this->user);
         $smarty->assignGlobal('auth', $this);
         return true;
     }
     return false;
 }
예제 #2
0
파일: install.php 프로젝트: cruide/wasp
 public function anyDefault()
 {
     global $database;
     $schema = $database->connection()->getSchemaBuilder();
     if (!$schema->hasTable('user_groups')) {
         $schema->create('user_groups', function ($table) {
             $table->increments('id');
             $table->integer('parent_id')->index()->default(0);
             $table->string('name', 50)->index()->default('');
             $table->string('desctiption')->index()->default('');
             $table->smallInteger('level')->index()->default(0);
             $table->string('lng')->default('');
             $table->timestamps();
             $table->softDeletes();
         });
     }
     if (!$schema->hasTable('users')) {
         $schema->create('users', function ($table) {
             $table->bigIncrements('id');
             $table->integer('group_id')->index()->default(0);
             $table->string('password', 48)->default('')->index();
             $table->tinyInteger('blocked')->default(0)->index();
             $table->bigInteger('blocked_to')->default(0)->index();
             $table->timestamps();
             $table->softDeletes();
         });
     }
     if (!$schema->hasTable('user_contacts')) {
         $schema->create('user_contacts', function ($table) {
             $table->bigIncrements('id');
             $table->bigInteger('user_id')->index()->default(0);
             $table->tinyInteger('type')->index()->default(Contact::TYPE_EMAIL);
             $table->string('value')->index()->default('');
             $table->tinyInteger('default')->index()->default(0);
             $table->timestamps();
             $table->softDeletes();
         });
     }
     if (!$schema->hasTable('user_sessions')) {
         $schema->create('user_sessions', function ($table) {
             $table->bigIncrements('id');
             $table->bigInteger('user_id')->index()->default(0);
             $table->string('session_id', 48)->index()->default('');
             $table->string('ip_address', 12)->index()->default('');
             $table->bigInteger('stamp')->index()->default(0);
             $table->timestamps();
             $table->softDeletes();
         });
     }
     if (!$schema->hasTable('user_profiles')) {
         $schema->create('user_profiles', function ($table) {
             $table->bigIncrements('id');
             $table->bigInteger('user_id')->index()->default(0);
             $table->string('nicname', 32)->index()->default('');
             $table->string('first_name', 150)->index()->default('');
             $table->string('middle_name', 150)->index()->default('');
             $table->string('last_name', 150)->index()->default('');
             $table->enum('gender', ['MALE', 'FEMALE', 'OTHER'])->index()->default('MALE');
             $table->date('birthday')->index();
             $table->bigInteger('stamp')->index()->default(0);
             $table->timestamps();
             $table->softDeletes();
         });
     }
     /**
      * Install groups
      */
     foreach ($this->groups as $level => $name) {
         $group = new Group();
         $group->name = $name;
         $group->level = $level;
         $group->lng = snake_case($name);
         $group->save();
     }
     unset($level, $name, $group);
     /**
      * Create SuperUser
      */
     $user = new User();
     $user->group_id = 1;
     $user->password = password_crypt('toor');
     $user->save();
     $userAuth = new Contact();
     $userAuth->user_id = $user->id;
     $userAuth->type = Contact::TYPE_EMAIL;
     $userAuth->value = '*****@*****.**';
     $userAuth->default = 1;
     $userAuth->save();
     $userProfile = new Profile();
     $userProfile->user_id = $user->id;
     $userProfile->nicname = 'SuperUser';
     $userProfile->save();
     return 'Installation success!';
 }