Skip to content

Commit

Permalink
更新用户信息。。。没写完
Browse files Browse the repository at this point in the history
  • Loading branch information
xsir317 committed Nov 25, 2014
1 parent 124a6f9 commit 770c21c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
4 changes: 4 additions & 0 deletions publisher/app/controllers/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public function editServer()
{
$server = Server::find($id);
}
if($server && !Auth::user()->pj_is_mine($server->project_id))
{
App::abort(403,'Not your project');
}
$project_id = intval(Input::get("project_id"));
//权限
if(!Auth::user()->pj_is_mine($project_id))
Expand Down
64 changes: 59 additions & 5 deletions publisher/app/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,69 @@ public function all()
return View::make("users/list",array("users"=>User::all()));
}

//添加用户
//添加、修改用户
public function edit()
{

}
{
if(!Auth::user()->is_superadmin)
{
App::abort(403, 'Unauthorized action.');
}
$id = intval(Input::get('id'));
$user = null;
if($id)
{
$user = User::find($id);
}
$error = '';
if (Request::isMethod('post'))
{
$username = trim(Input::get('username'));
$password = trim(Input::get('password'));
$is_superadmin = trim(Input::get('is_superadmin'));
$project_ids = Input::get('project');
if($user)
{
if($password)
{
$user->password = Hash::make($password);
}
}
else
{
if(!$username || !$password)
{
$error = '信息不完整!';
}
if(User::where("username",$username)->get())
{
$error = '用户名不能和已有用户重复';
}
}
if(!$error)
{
if(!$user)
{
$user = new User;
$user->username = $username;
$user->password = Hash::make($password);
}
$user->save();
//处理传过来的项目id数组
return Redirect::route('users/index');
}
}
//当前用户拥有的所有项目
$projects = Project::whereIn('id',Auth::user()->pj_ids())->get();
$prj_list = array();
foreach ($projects as $value) {
$prj_list[$value->id] = $value->title;
}
return View::make('users/edit',array('user'=>$user,'error' => $error));
}

//改密码
public function changepwd()
{

}
}
18 changes: 6 additions & 12 deletions publisher/app/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,14 @@ class User extends Eloquent implements UserInterface, RemindableInterface {

public function pj_ids()
{
if(!Session::has("pj_ids"))
if($this->is_superadmin)
{
$ids = array();
if($this->is_superadmin)
{
$ids = Project::lists("id");
}
else
{
$ids = UserProjectRelation::where('uid',$this->id)->lists("prj_id");
}
Session::put("pj_ids",$ids);
return Project::lists("id");
}
else
{
return UserProjectRelation::where('uid',$this->id)->lists("prj_id");
}
return Session::get("pj_ids");
}

public function pj_is_mine($id)
Expand Down

0 comments on commit 770c21c

Please sign in to comment.