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; }
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!'; }
public function anyAdd() { $confirm = $this->input->post('confirm'); $form = $this->input->post('form'); $errors = []; if (!empty($confirm) && $confirm == 'ok') { $validator = new \Wasp\Validator($form, $this->validation); if (!$validator->checkAll()) { $errors = $validator->getMessages(); } $check_user = $this->users->getByEmail($form['email']); $user_data = []; if (!empty($check_user->id)) { if (!isset($errors['email']) || !is_array($errors['email'])) { $errors['email'] = []; } $errors['email'][] = 'Такой пользователь уже есть'; } if (!is_alphanum($form['passwd1']) || !is_alphanum($form['passwd2']) || wasp_strlen($form['passwd1']) > 16 || wasp_strlen($form['passwd1']) < 6 || wasp_strlen($form['passwd2']) > 16 || wasp_strlen($form['passwd2']) < 6 || $form['passwd1'] != $form['passwd2']) { if (!isset($errors['passwd1']) || !is_array($errors['passwd1'])) { $errors['passwd1'] = []; } $errors['passwd1'][] = 'Неверное указан пароль'; } if (array_count($errors) == 0) { $current_user = $this->auth->getAuthUser(); $group_level = $this->users->getGroupLevel($form['group_id']); $passwd = password_crypt($form['passwd1']); $user_data['email'] = $form['email']; $user_data['password'] = $passwd; if ($this->users->groupIdExists($form['group_id']) && ($group_level < $current_user->group->level || $this->auth->isRoot())) { $user_data['group_id'] = intval($form['group_id']); $user_data['blocked'] = intval($form['blocked']); } if ($this->auth->isAdmin()) { foreach ($form as $key => $val) { if (!array_key_isset($key, $user_data)) { $user_data[$key] = $val; } } } $id = $this->users->create($user_data); redirect(['controller' => 'users', 'method' => 'edit', 'id' => $id, 'message' => 'Пользователь успешно добавлен в систему.']); } } $this->layout->useThemeCss('datepicker.css')->useThemeJs('bootstrap-datepicker.js', false); return $this->ui->assign('errors', $errors)->assign('form', $form)->assign('groups', $this->users->getGroups())->fetch('users/add'); }