public static function install() { //\Migrate::latest(); // Insert the default settings and user groups echo "\nInserting defaults..."; \DB::insert('settings')->columns(array('setting', 'value'))->values(array('title', 'LitePress'))->execute(); \DB::insert('settings')->columns(array('setting', 'value'))->values(array('theme', 'default'))->execute(); \DB::insert('settings')->columns(array('setting', 'value'))->values(array('validate_users', '0'))->execute(); $groups = array(array('Admin', 1, 1, 1, 1, 1), array('Author', 0, 1, 1, 1, 1), array('Reader', 0, 0, 0, 0, 0), array('Validating', 0, 0, 0, 0, 0), array('Guest', 0, 0, 0, 0, 0)); foreach ($groups as $group) { $row = \Model_Group::forge(array('name' => $group[0], 'is_admin' => $group[1], 'is_author' => $group[2], 'create_articles' => $group[3], 'edit_articles' => $group[4], 'delete_articles' => $group[5])); $row->save(); } // Create an admin account echo "\nCreating admin account..."; $admin_password = strtolower(substr(sha1(time() . rand(1, 100)), 0, 5)); $admin = \Model_User::forge(array('name' => 'Admin', 'username' => 'Admin', 'password' => $admin_password, 'email' => '*****@*****.**', 'group_id' => 1)); $admin->save(); echo "\nAdmin account created,", "\nUsername: Admin\n", "Password: " . $admin_password; }
public function action_create($group_type = false) { \View::set_global('title', 'Add New Group'); if (\Input::post()) { $val = Model_Group::validate('create'); if ($val->run()) { // Get POST values $insert = \Input::post(); $item = Model_Group::forge($insert); try { $item->save(); \Messages::success('Group successfully created.'); \Response::redirect(\Input::post('update', false) ? \Uri::create('admin/product/group/update/' . $item->id) : \Input::referrer(\Uri::admin('current'))); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create group</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create group</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } // Keep existing messages \Messages::instance()->shutdown(); \Response::redirect('admin/product/group/list' . ($group_type ? '/' . $group_type : '')); }