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