添加用户功能完成;修改项目#添加用户接口(增加重复性验证)
This commit is contained in:
parent
921bbc3f95
commit
b206bfa9b2
|
@ -52,25 +52,24 @@ class ProjectsController < ApplicationController
|
|||
#=============================================>项目添加用户
|
||||
|
||||
def addUsers
|
||||
#Todo
|
||||
uid = params[:user_id]
|
||||
register = session[:user_id]
|
||||
#username = params[:username]
|
||||
pid = params[:project_id]
|
||||
params_pu = {project_id: pid,user_id: uid}
|
||||
pu = Projects_user.new(params_pu)
|
||||
pu.save
|
||||
content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name
|
||||
puts content
|
||||
params_note = {user_id: uid,content: content,category: 2,project_id: pid}
|
||||
note = Note.new(params_note)
|
||||
note.save!
|
||||
#puts Note.find_by(id: note.id).inspect
|
||||
# now = Datetime.now
|
||||
# note.created_at = now
|
||||
# note.updated_at = now
|
||||
note.save!
|
||||
render :json => {:code => 0}
|
||||
uid = User.find_by(email:params[:email]).id# 需要添加的用户
|
||||
register = session[:user_id]# 当前用户
|
||||
pid = params[:project_id]
|
||||
# 检查该项目中是否已经有要添加的用户
|
||||
pu_exist=Projects_user.find_by(project_id:pid,user_id:uid)
|
||||
if pu_exist.nil?# 不存在
|
||||
params_pu = {project_id: pid,user_id: uid}
|
||||
pu = Projects_user.new(params_pu)
|
||||
pu.save
|
||||
content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name
|
||||
puts content
|
||||
params_note = {user_id: uid,content: content,category: 2,project_id: pid}
|
||||
note = Note.new(params_note)
|
||||
note.save!
|
||||
render :json => {:code => 0}
|
||||
else# 存在
|
||||
render json:current_user.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================>项目详情
|
||||
|
@ -117,6 +116,7 @@ class ProjectsController < ApplicationController
|
|||
render json:current_user.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def project_params
|
||||
params.require(:project).permit(:name,:content,:id)
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
</div>
|
||||
<!-- /.box-body -->
|
||||
<div class="box-footer">
|
||||
<button onclick="cy_submit()" class="btn btn-primary pull-right">提交修改</button>
|
||||
<button onclick="basic_alter()" class="btn btn-primary pull-right">提交修改</button>
|
||||
</div>
|
||||
<!-- /.box-footer -->
|
||||
</div>
|
||||
|
@ -92,7 +92,6 @@
|
|||
</div>
|
||||
<!-- /.box-header -->
|
||||
<!-- form start -->
|
||||
<form role="form">
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-9 col-md-push-2">
|
||||
|
@ -112,16 +111,15 @@
|
|||
<!-- /.row -->
|
||||
<div class="form-group row has-feedback">
|
||||
<div class="col-sm-6 col-md-push-2">
|
||||
<input type="text" class="form-control" value="" id="cy_new_user" name="address" placeholder="输入新成员邮箱">
|
||||
<input type="text" class="form-control" value="" id="new_user_email" placeholder="输入新成员邮箱">
|
||||
</div>
|
||||
<div class="col-sm-2 col-md-push-2">
|
||||
<button onclick="cy_addUser()" class="btn btn-primary btn-success">添加成员</button>
|
||||
<button onclick="addUser()" class="btn btn-primary btn-success">添加成员</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ./form-group -->
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ./col -->
|
||||
|
@ -180,32 +178,64 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
function cy_addUser(){
|
||||
$.ajax({
|
||||
type:"post",
|
||||
dataType:"json",
|
||||
url:"/projects.json",
|
||||
data:{
|
||||
"user_id":$("#cy_new_user"),
|
||||
"project_id":parent.LoginUserInfo.selectProject
|
||||
},
|
||||
statusCode: {
|
||||
200: function(rpstr) {// 请求成功
|
||||
var robj = eval('('+rpstr+')');
|
||||
if(robj["code"]==0){
|
||||
window.location.reload();
|
||||
}
|
||||
else{
|
||||
//todo
|
||||
}
|
||||
function addUser(){
|
||||
var new_user_email=$("#new_user_email").val();
|
||||
if( new_user_email.length>0 ){
|
||||
// 邮箱对应的用户是否存在
|
||||
var exist;
|
||||
$.ajax({
|
||||
type: "get",
|
||||
dataType: "json",
|
||||
url:"/users/emailExist.json",
|
||||
async:false,// 强制同步
|
||||
data: {
|
||||
"email":new_user_email
|
||||
},
|
||||
401:function(){// 未授权
|
||||
|
||||
statusCode: {
|
||||
200: function(data) {// 请求成功
|
||||
//alert(data);
|
||||
if( data=='1' )
|
||||
exist=true;
|
||||
else
|
||||
exist=false;
|
||||
},
|
||||
422:function(){
|
||||
alert("输入不符合要求,请重新输入!");
|
||||
},
|
||||
401:function(){// 未授权
|
||||
alert("用户名或密码错误!");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if( exist ){// 邮箱存在
|
||||
$.ajax({
|
||||
type:"post",
|
||||
dataType:"json",
|
||||
async:false,// 强制同步
|
||||
url:"/projects/users.json",
|
||||
data:{
|
||||
"email":new_user_email,
|
||||
"project_id":parent.LoginUserInfo.selectProject
|
||||
},
|
||||
statusCode: {
|
||||
200: function(response) {// 请求成功
|
||||
alert("添加成功!");
|
||||
window.location.reload();
|
||||
},
|
||||
422:function(){
|
||||
alert("用户已经在项目中!")
|
||||
}
|
||||
}
|
||||
});
|
||||
}else{// 邮箱不存在
|
||||
alert("该邮箱对应的用户不存在!")
|
||||
}
|
||||
}else{
|
||||
alert("请输入完整!");
|
||||
}
|
||||
// 添加用户
|
||||
}
|
||||
function cy_deleteUser(id){
|
||||
function deleteUser(id){
|
||||
return;
|
||||
$.ajax({
|
||||
type:"delete",
|
||||
|
@ -232,7 +262,7 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
function cy_submit(){
|
||||
function basic_alter(){
|
||||
var project_content=$("#project_content").val();
|
||||
var project_name=$("#project_name").val();
|
||||
if( project_name.length>0 && project_content.length>0 ){
|
||||
|
|
Loading…
Reference in New Issue