添加用户功能完成;修改项目#添加用户接口(增加重复性验证)
This commit is contained in:
parent
921bbc3f95
commit
b206bfa9b2
|
@ -52,25 +52,24 @@ 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]
|
pid = params[:project_id]
|
||||||
#username = params[:username]
|
# 检查该项目中是否已经有要添加的用户
|
||||||
pid = params[:project_id]
|
pu_exist=Projects_user.find_by(project_id:pid,user_id:uid)
|
||||||
params_pu = {project_id: pid,user_id: uid}
|
if pu_exist.nil?# 不存在
|
||||||
pu = Projects_user.new(params_pu)
|
params_pu = {project_id: pid,user_id: uid}
|
||||||
pu.save
|
pu = Projects_user.new(params_pu)
|
||||||
content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name
|
pu.save
|
||||||
puts content
|
content = User.find_by(id: register).name + "邀请您进入项目" + Project.find_by(id: pid).name
|
||||||
params_note = {user_id: uid,content: content,category: 2,project_id: pid}
|
puts content
|
||||||
note = Note.new(params_note)
|
params_note = {user_id: uid,content: content,category: 2,project_id: pid}
|
||||||
note.save!
|
note = Note.new(params_note)
|
||||||
#puts Note.find_by(id: note.id).inspect
|
note.save!
|
||||||
# now = Datetime.now
|
render :json => {:code => 0}
|
||||||
# note.created_at = now
|
else# 存在
|
||||||
# note.updated_at = now
|
render json:current_user.errors, status: :unprocessable_entity
|
||||||
note.save!
|
end
|
||||||
render :json => {:code => 0}
|
|
||||||
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(){
|
||||||
$.ajax({
|
var new_user_email=$("#new_user_email").val();
|
||||||
type:"post",
|
if( new_user_email.length>0 ){
|
||||||
dataType:"json",
|
// 邮箱对应的用户是否存在
|
||||||
url:"/projects.json",
|
var exist;
|
||||||
data:{
|
$.ajax({
|
||||||
"user_id":$("#cy_new_user"),
|
type: "get",
|
||||||
"project_id":parent.LoginUserInfo.selectProject
|
dataType: "json",
|
||||||
},
|
url:"/users/emailExist.json",
|
||||||
statusCode: {
|
async:false,// 强制同步
|
||||||
200: function(rpstr) {// 请求成功
|
data: {
|
||||||
var robj = eval('('+rpstr+')');
|
"email":new_user_email
|
||||||
if(robj["code"]==0){
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//todo
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
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;
|
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