示例#1
0
 public function run()
 {
     $admin = array('displayName' => 'Andres Rangel', 'email' => '*****@*****.**', 'password' => bcrypt('12345'), 'active' => 1, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'image' => '55fa8e7a612e4.png');
     $user = array('displayName' => 'User Andres', 'email' => '*****@*****.**', 'password' => bcrypt('12345'), 'active' => 0, 'activation_code' => md5(microtime() . Config::get('app.key')), 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'image' => '55fa8e7a612e4.png');
     $permissions = array(['display_name' => 'Manage Admin', 'name' => 'manage_admin', 'description' => 'Give permission to user to access the admin area.', 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")], ['display_name' => 'Manage Own Data', 'name' => 'manage_own', 'description' => 'Allow users to manage their own data.', 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]);
     $roles = array(['display_name' => 'Admin', 'name' => 'admin', 'description' => 'Give user full permission to site functions.', 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")], ['display_name' => 'User', 'name' => 'user', 'description' => 'Standard User', 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]);
     // Create Permissions
     DB::table('permissions')->delete();
     $statement = "ALTER TABLE permissions AUTO_INCREMENT = 1;";
     DB::unprepared($statement);
     DB::table('permissions')->insert($permissions);
     // Create Roles
     DB::table('roles')->delete();
     $statement = "ALTER TABLE roles AUTO_INCREMENT = 1;";
     DB::unprepared($statement);
     DB::table('roles')->insert($roles);
     // Clear relationships
     DB::table('permission_role')->delete();
     $statement = "ALTER TABLE permission_role AUTO_INCREMENT = 1;";
     DB::unprepared($statement);
     DB::table('role_user')->delete();
     $statement = "ALTER TABLE role_user AUTO_INCREMENT = 1;";
     DB::unprepared($statement);
     // Create Users
     DB::table('users')->delete();
     $statement = "ALTER TABLE users AUTO_INCREMENT = 1;";
     DB::unprepared($statement);
     DB::table('users')->insert($admin);
     DB::table('users')->insert($user);
     // Attach permission to role
     $role = $this->role->find(1);
     $role2 = $this->role->find(2);
     /*$perm_1 = $this->permission->find(1);
             $role->attachPermission($perm_1);
     
             $perm_2 = $this->permission->find(2);
             $role2->attachPermission($perm_2);*/
     // Attach role to user
     $user = User::find(1);
     $user->roles()->attach($role);
     $user = User::find(2);
     $user->roles()->attach($role2);
 }
示例#2
0
 /**
  * Update signed in user's profile.
  */
 public function updateUser(Request $request)
 {
     /**
      * Get Image base64, decode it and save it.
      */
     $input = Input::all();
     //return $input;
     $file = $input['file'];
     $search_str = ['data:image/png;base64,', 'data:image/jpeg;base64,'];
     $uploadImage = false;
     $uploadFile = strpos($file, "data:");
     /**
      * If the string file contains data save image
      */
     if ($uploadFile !== false) {
         $img = str_replace($search_str, '', $file);
         $img = str_replace(' ', '+', $img);
         $data = base64_decode($img);
         $imageName = uniqid();
         $imgFile = public_path('uploads') . "/" . $imageName . '.png';
         $image = Image::make($data);
         $image->save($imgFile, 100);
         $uploadImage = true;
     }
     /**
      * Update user
      */
     $user = User::find($request['user']['sub']);
     $user->displayName = $request->input('displayName');
     $user->email = $request->input('email');
     if ($uploadImage) {
         $user->image = $imageName . '.png';
     }
     $user->save();
     $token = $this->createToken($user);
     Activity::log("You have updated your basic user information", $user->id);
     return response()->json(['token' => $token]);
 }
示例#3
0
 /**
  * @param Request $request
  */
 public function destroyUser(Request $request)
 {
     $user = User::find($request->input('id'));
     $user->delete();
     return Response::json(['success', true]);
 }
示例#4
0
 public function deleteLocation(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $location = $user->locations()->find($request->input('Id'))->delete();
     Activity::log("You have deleted a Location in your profile", $user->id);
     return response()->json('Success', "Your location has been delete.");
 }