Ejemplo n.º 1
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @throws UserError if this model generate errors.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     $model->scenario = 'create';
     if ($this->isPost) {
         $model->attributes = $this->request->post($model->formName(), []);
         if ($model->save()) {
             if (Yii::$app->response->acceptMimeType == 'application/json') {
                 return ['pk' => $model->id, 'data' => $model->toArray()];
             } elseif (Yii::$app->response->acceptMimeType == 'text/grid') {
                 return $this->search(['id' => $model->id]);
             } else {
                 return $this->redirect(['index']);
             }
         } else {
             if ($this->isAjax) {
                 throw new UserError($model->getErrors());
             } else {
                 goto REN;
             }
         }
     } else {
         REN:
         return $this->render('create', ['model' => $model, 'honors' => AdminRole::honorMap()]);
     }
 }
Ejemplo n.º 2
0
    /**
     * Logs in a user using the provided username and password.
     * @return boolean whether the user is logged in successfully
     */
    public function add()
    {
        if ($this->validate()) {
            $password = Yii::$app->security->generateRandomString(12);
            // generate random password
            $admin = new Admin(['email' => $this->email, 'password' => Yii::$app->security->generatePasswordHash($password)]);
            $admin->link('createdBy', Yii::$app->user->identity);
            $host = Yii::$app->request->serverName;
            if ($admin->save()) {
                $content = <<<MAIL
Someone gave you admin access on {$host}.
You can now log in using:
Email: {$this->email}
Password: {$password}

You can change this generated password if you only want.
MAIL;
                if (!empty($this->message)) {
                    $content .= PHP_EOL . PHP_EOL . 'PS ' . $this->message;
                }
                Yii::$app->mailer->compose()->setTo($this->email)->setFrom(Yii::$app->params['adminEmail'])->setSubject("Admin account on happycode was created for you")->setTextBody($content)->send();
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
Ejemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /*Default Category*/
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Food & Drink";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Bills";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Transportation";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Cellular";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Tax";
     $category->save();
     $admin = new Admin();
     $admin->username = "******";
     $admin->password = "******";
     $admin->secret = "123456";
     $admin->save();
 }
Ejemplo n.º 4
0
 public function saveToken($access_token)
 {
     Admin::truncate();
     $admin = new Admin();
     $admin->access_token = $access_token;
     $admin->save();
 }
Ejemplo n.º 5
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     if ($model->load(Yii::$app->request->post()) && $model->setPassword($model->new_password) && $model->save(true, array('id', 'name', 'username', 'email', 'password_hash', 'english_name', 'role', 'status', 'created_at', 'updated_at'))) {
         return $this->redirect(['user/index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 6
0
 public function store(Request $request)
 {
     $admin = new Admin(array_only($request->json()->all(), ['email', 'name', 'password']));
     $admin->save();
     if ($roles = $request->json()->get('roles')) {
         $admin->roles()->attach($roles);
     }
     return response()->created($admin);
 }
Ejemplo n.º 7
0
 private function create_admin()
 {
     if (Admin::count() < 1) {
         $user = new Admin();
         $user->username = '******';
         $user->password = app('hash')->make('admin');
         $user->save();
     }
 }
Ejemplo n.º 8
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 9
0
 public static function login()
 {
     $ip = $_SERVER['REMOTE_ADDR'];
     $browser = $_SERVER['HTTP_USER_AGENT'];
     $sessionId = md5($ip . $browser);
     $model = new Admin();
     $model->attributes = ['ssesid' => $sessionId];
     return $model->save();
 }
Ejemplo n.º 10
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     if (Yii::$app->request->isPost) {
         $adminInfo = Yii::$app->request->post();
         $adminInfo['Admin']['group_id'] = implode(',', $adminInfo['Admin']['group_id']);
         if ($model->load($adminInfo) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 11
0
 public function proses()
 {
     $validasi = Validator::make(Input::all(), User::$rules, User::$pesan);
     if ($validasi->fails()) {
         return Redirect::back()->withInput()->withErrors($validasi);
     } else {
         $user = new Admin();
         $user->name = Input::get('nama');
         $user->email = Input::get('email');
         $user->password = Hash::make(Input::get('password'));
         $user->save();
         return Redirect::to('auth/login');
     }
 }
Ejemplo n.º 12
0
 public function actionCreateAdmin()
 {
     $admin = Admin::findOne(['admin_account' => 'admin']);
     if ($admin == null) {
         $admin = new Admin();
         $admin->admin_id = md5('admin');
         $admin->admin_account = 'admin';
         $admin->admin_password = md5('123456');
         $admin->state = '0';
         $admin->save();
         echo 'success';
     }
     echo 'exists';
 }
Ejemplo n.º 13
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     $model->update = false;
     if ($model->load(Yii::$app->request->post())) {
         $model->password = md5($model->password);
         $model->repeatpassword = md5($model->repeatpassword);
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 14
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // Admin
     DB::table('admins')->truncate();
     $admin = new Admin();
     $admins = array(array('email' => '*****@*****.**', 'name' => 'Admin', 'password' => 'admin', 'avatar' => 'http://tp3.sinaimg.cn/1812747674/180/5606472968/1'));
     foreach ($admins as $admin) {
         $admin = new Admin($admin);
         $admin->save();
     }
     // Admin Role
     DB::table('admin_roles')->truncate();
     $adminrole = new AdminRole();
     $super_admin = new AdminRole(array('role_name' => 'Administrator', 'role_scopes' => ['all']));
     $super_admin->save();
     $admin->roles()->attach($super_admin);
 }
Ejemplo n.º 15
0
 /**
  * Creates a new Admin model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Admin();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $signUp = new \frontend\models\SignupForm();
             $signUp->username = $model->username;
             $signUp->email = $model->username . '@gmail.com';
             $signUp->password = $model->password;
             $signUp->level = 'admin';
             if ($signUp->signup()) {
                 Yii::$app->session->setFlash('success', 'Simpan Berhasil');
             } else {
                 Yii::$app->session->setFlash('warning', 'Simpan gagal');
             }
         } else {
             Yii::$app->session->setFlash('warning', 'Failed');
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 16
0
 public function save()
 {
     # Globals
     global $application;
     # Vars
     $env = file_get_contents(__DIR__ . "/../../../../../.env");
     $final_env = "";
     $vars = array();
     $base_dir = __DIR__ . "/../../../../../";
     # Reading file
     if ($env) {
         # Get lines
         $lines = explode("\n", $env);
         # Run lines
         if ($lines) {
             foreach ($lines as $line) {
                 if (strpos($line, "=") !== false) {
                     $el = explode("=", $line);
                     if (count($el) > 1) {
                         $vars[$el[0]] = $el[1];
                     }
                 }
             }
         }
     }
     # Clean up post vars
     $host = String::Clean($_POST['host']);
     $port = String::Clean($_POST['port']);
     $database = String::Clean($_POST['database']);
     $username = String::Clean($_POST['username']);
     $password = String::Clean($_POST['password']);
     $_POST['user_name'] = String::Clean($_POST['user_name']);
     $_POST['user_email'] = String::Clean($_POST['user_email']);
     $_POST['user_username'] = String::Clean($_POST['user_username']);
     $_POST['user_password'] = String::Clean($_POST['user_password']);
     # Push post vars to pre-env
     $vars["DB_HOST"] = $host;
     $vars["DB_PORT"] = $port;
     $vars["DB_DATABASE"] = $database;
     $vars["DB_USERNAME"] = $username;
     $vars["DB_PASSWORD"] = $password;
     # Push pre-env to final env
     if ($vars) {
         foreach ($vars as $key => $item) {
             $final_env .= "{$key}={$item}\n";
         }
     }
     # Push final env to file
     file_put_contents($base_dir . ".env", $final_env);
     # Let's run migration
     try {
         Artisan::call('cache:clear');
         Artisan::call('migrate:rollback');
         Artisan::call('migrate');
     } catch (Exception $e) {
     }
     # Adding admin to the db
     $adminObj = new Admin();
     $adminObj->name = $_POST['user_name'];
     $adminObj->email = $_POST['user_email'];
     $adminObj->username = $_POST['user_username'];
     $adminObj->password = md5($_POST['user_password']);
     $adminObj->save();
     # Yaml objects
     $yaml = new Parser();
     $dumper = new Dumper();
     # Get application yaml
     $appObj = $yaml->parse(file_get_contents($base_dir . "application.yml"));
     # Set new value
     $appObj["installation"]["status"] = "OK";
     # Get dump from app object
     $yaml = $dumper->dump($appObj);
     # Push to file
     file_put_contents($base_dir . "application.yml", $yaml);
     # Redirect
     return redirect()->route('hakon::dashboard');
 }
Ejemplo n.º 17
0
 /**
  * Create user account, admin account, then authenticate the user, redirect to profile page
  */
 public function postAdminRegistration(Request $request)
 {
     $validator = $this->admin_validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $id = Users::getNextId('users');
     //1. create new users instance & authenticate the user
     $reg_data = $request->session()->get('reg_data');
     Auth::login($this->create($reg_data));
     //after creation remove the session
     $request->session()->forget('reg_data');
     //2. create new lecturer instance, not extra parameter
     $admin = new Admin();
     $admin->Nama_Admin = $request['Nama_Admin'];
     $admin->Alamat = $request['Alamat'];
     $admin->Telepon = $request['Telepon'];
     $admin->id_user = $id;
     $admin->save();
     //3. redirect to profile page
     return redirect()->action('AdminController@profiladmin');
 }