个人资料修改功能
This commit is contained in:
parent
c9c63eeb85
commit
c234a8d2cb
|
@ -4,6 +4,54 @@ module Mobile
|
|||
class Users < Grape::API
|
||||
resource :users do
|
||||
|
||||
desc "我的资料"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
get 'get_userinfo' do
|
||||
authenticate!
|
||||
present :data, current_user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "上传头像"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :imgdata, type: String
|
||||
end
|
||||
|
||||
post 'upload_head' do
|
||||
authenticate!
|
||||
#直接生成头像
|
||||
dirPath = "public/images/avatars/User"
|
||||
|
||||
fileDir = dirPath + "/"+current_user.id.to_s
|
||||
begin
|
||||
File.open(fileDir,'wb'){ |f| f.write(Base64.decode64(params[:imgdata].split(",")[1])) }
|
||||
present :status, 0
|
||||
rescue
|
||||
present :status, -1
|
||||
end
|
||||
end
|
||||
|
||||
desc "解除绑定"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
post 'user_unbind' do
|
||||
authenticate!
|
||||
|
||||
user = current_user
|
||||
uw = user.user_wechat
|
||||
|
||||
us = UsersService.new
|
||||
us.wechat_unbind user.user_wechat
|
||||
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "查询是否已绑定"
|
||||
params do
|
||||
requires :openid, type: String, desc: 'wechat openid'
|
||||
|
@ -222,23 +270,11 @@ module Mobile
|
|||
present :status,0
|
||||
end
|
||||
|
||||
desc "我的资料"
|
||||
desc "修改我的资料"
|
||||
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
get 'my_userinfo' do
|
||||
authenticate!
|
||||
present :data, current_user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "我的资料"
|
||||
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :nickname, type: String
|
||||
requires :lastname, type: String
|
||||
requires :sex, type: Integer
|
||||
requires :mail, type: String
|
||||
end
|
||||
|
@ -250,7 +286,7 @@ module Mobile
|
|||
message = ""
|
||||
|
||||
#昵称 不能超过30个字符
|
||||
if params[:nickname].length > 30 then
|
||||
if params[:lastname].length > 30 then
|
||||
message = "姓名不能超过30个字符!"
|
||||
status = -1
|
||||
end
|
||||
|
@ -272,20 +308,23 @@ module Mobile
|
|||
begin
|
||||
g.edit_user(user.gid, :email => params[:mail])
|
||||
rescue
|
||||
logger.error "sync user's email of gitlab failed!"
|
||||
Rails.logger.error "sync user's email of gitlab failed!"
|
||||
end
|
||||
end
|
||||
|
||||
user.lastname = params[:nickname]
|
||||
user.mail = params[:mail]
|
||||
|
||||
user.lastname = params[:lastname]
|
||||
|
||||
se = user.extensions
|
||||
|
||||
se.gender = params[:sex]
|
||||
|
||||
|
||||
if user.save && se.save
|
||||
status = 0
|
||||
else
|
||||
message = "保存数据失败!"
|
||||
message = "该邮箱地址已被使用!"
|
||||
status = -1
|
||||
end
|
||||
end
|
||||
|
@ -298,22 +337,6 @@ module Mobile
|
|||
present :message, message
|
||||
end
|
||||
end
|
||||
|
||||
desc "解除绑定"
|
||||
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
|
||||
post 'unbind' do
|
||||
authenticate!
|
||||
|
||||
us = UsersService.new
|
||||
us.wechat_unbind uw
|
||||
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,6 +39,10 @@ module Mobile
|
|||
|
||||
expose :id
|
||||
#头像
|
||||
expose :login
|
||||
expose :lastname
|
||||
#邮箱地址
|
||||
expose :mail
|
||||
expose :nickname
|
||||
#真名
|
||||
user_expose :img_url
|
||||
|
@ -51,8 +55,6 @@ module Mobile
|
|||
#我的二维码
|
||||
#工作单位
|
||||
user_expose :work_unit
|
||||
#邮箱地址
|
||||
user_expose :mail
|
||||
#地区
|
||||
user_expose :location
|
||||
#签名
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#coding=utf-8
|
||||
class UsersService
|
||||
include ApplicationHelper
|
||||
include AccountHelper
|
||||
|
@ -323,8 +324,14 @@ class UsersService
|
|||
user = uw.user
|
||||
|
||||
#发重新绑定的微信模版消息
|
||||
|
||||
type = "login"
|
||||
title = "尊敬的用户,您已解除绑定。"
|
||||
key1 = "个人原因"
|
||||
remark = "点击进入重新绑定。"
|
||||
|
||||
ws = WechatService.new
|
||||
ws.rebind_notice user.id, "login", user.id, "尊敬的用户,您已解除绑定。", "个人原因",format_time(Time.now), "点击进入重新绑定"
|
||||
ws.rebind_notice user.id, type, user.id, title, key1,format_time(Time.now), remark
|
||||
|
||||
uw.user_id = nil
|
||||
uw.delete
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<div class="post-container">
|
||||
<div loading-spinner></div>
|
||||
<div class="blue-title">编辑资料</div>
|
||||
<div class="blank-row mt10">
|
||||
<div class="upload-input-container img-circle fl ml10 mt4">
|
||||
<!--<input class="upload-input" accept="image/*" multiple="" type="file">-->
|
||||
<input class="upload-input" type="file" capture="camera" accept="image/*" load-head>
|
||||
<img ng-src="{{replaceUrl(user.img_url)}}" width="30" class="fl ml10 img-circle mt4" />
|
||||
</div>
|
||||
<span class="fl ml25">{{user.login}}</span><span ng-click="unbind()" class="fr f13 mr10 c-blue">解除绑定</span><div class="cl"></div></div>
|
||||
|
||||
<form name="regFrm" novalidate>
|
||||
|
||||
<div class="course-list-row f13 c-grey3 mt10"><span class="fl ml15 c-grey3">姓名</span><input class="new-class-input ml25" ng-model="lastname" placeholder="请输入您的姓名全称" maxlength="30" /></div>
|
||||
<div class="course-list-row f13 c-grey3 mt10">
|
||||
<span class="c-grey3 select-text">性别</span>
|
||||
<div class="select-container">
|
||||
<select ng-model="gender" class="select-model">
|
||||
<!--<option selected="selected">请选择您的性别</option>-->
|
||||
<option ng-selected="sex==0">男</option>
|
||||
<option ng-selected="sex==1">女</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="course-list-row f13 c-grey3 mt10">
|
||||
<span class="fl ml15 c-grey3">邮箱</span>
|
||||
<input class="new-class-input ml25" type="email" name="email" ng-model="mail" placeholder="请输入您的邮箱地址" maxlength="60" />
|
||||
<div ng-show="regFrm.$submitted || regFrm.email.$touched">
|
||||
<span class="f12 c-red fl" ng-show="regFrm.email.$error.required">电子邮箱地址不能为空</span>
|
||||
<span class="f12 c-red fl" ng-show="regFrm.email.$error.email">电子邮箱地址不合法</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottom-tab-wrap mt10">
|
||||
<a ng-click="cancel()" class="weixin-tab c-grey border-top">取消</a>
|
||||
<a ng-click="confirm(regFrm)" ng-class="[{'btn-disabled':!regFrm.$valid} ]" class="weixin-tab link-blue2 border-top">确定</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<my-alert message="alertService_1.message" title="alertService_1.title" visible="alertService_1.visible" cb="alertService_1.cb"></my-alert>
|
||||
<my-alert2 message="alertService_2.message" title="alertService_2.title" visible="alertService_2.visible" cb="alertService_2.cb"></my-alert2>
|
||||
</div>
|
|
@ -0,0 +1,103 @@
|
|||
app.controller('EditUserInfoController', ['$scope', 'config','$http', 'auth','$location','$routeParams','alertService','rms','common','$timeout','wx', function($scope, config, $http, auth, $location, $routeParams,alertService,rms,common,$timeout,wx){
|
||||
// common.checkLogin();
|
||||
|
||||
$scope.replaceUrl = function(url){
|
||||
return url;
|
||||
};
|
||||
|
||||
var vm = $scope;
|
||||
|
||||
//单弹框
|
||||
vm.alertService_1 = alertService.create();
|
||||
|
||||
//双弹框
|
||||
vm.alertService_2 = alertService.create();
|
||||
|
||||
vm.getuserinfo = function(){
|
||||
$http.get(config.apiUrl + 'users/get_userinfo?token='+auth.token()).then(
|
||||
function(response) {
|
||||
console.log(response.data);
|
||||
vm.user = response.data.data;
|
||||
vm.lastname = vm.user.lastname;
|
||||
vm.mail = vm.user.mail;
|
||||
vm.sex = vm.user.gender;
|
||||
if(vm.sex == 0){
|
||||
vm.gender = "男";
|
||||
}
|
||||
else{
|
||||
vm.gender = "女";
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
vm.getuserinfo();
|
||||
|
||||
vm.unbind = function(){
|
||||
vm.alertService_2.showMessage('提示', '是否确认解除绑定', function() {
|
||||
$http.post(config.apiUrl + "users/user_unbind",
|
||||
{token: auth.token()}
|
||||
).then(function (response) {
|
||||
if (response.data.status == 0) {
|
||||
vm.alertService_1.showMessage('提示', '解除绑定成功', function () {
|
||||
wx.closeWindow();
|
||||
});
|
||||
}
|
||||
else {
|
||||
vm.alertService_1.showMessage('提示', response.data.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
vm.cancel = function(){
|
||||
vm.alertService_2.showMessage('提示', '是否确认取消', function() {
|
||||
wx.closeWindow();
|
||||
});
|
||||
};
|
||||
|
||||
vm.confirm = function(frm){
|
||||
frm.$setSubmitted();
|
||||
|
||||
console.log(frm);
|
||||
if (!frm.$valid) {
|
||||
console.log(frm.$error);
|
||||
return;
|
||||
}
|
||||
|
||||
var sex = 0;
|
||||
if(vm.gender == "女"){
|
||||
sex = 1;
|
||||
}
|
||||
|
||||
if(vm.lastname == ""){
|
||||
vm.alertService_1.showMessage('提示', '姓名不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
if(vm.mail == ""){
|
||||
vm.alertService_1.showMessage('提示', '邮箱不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
// if(!(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.test(vm.mail))){
|
||||
// vm.alertService_1.showMessage('提示', '邮箱不合法');
|
||||
// return;
|
||||
// }
|
||||
|
||||
$http.post(config.apiUrl + "users/edit_userinfo",
|
||||
{token: auth.token(),lastname: vm.lastname, sex: sex, mail: vm.mail}
|
||||
).then(function(response){
|
||||
if(response.data.status == 0)
|
||||
{
|
||||
vm.alertService_1.showMessage('提示', '修改成功',function(){
|
||||
wx.closeWindow();
|
||||
});
|
||||
}
|
||||
else{
|
||||
vm.alertService_1.showMessage('提示', response.data.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
}]);
|
|
@ -1,25 +0,0 @@
|
|||
app.directive('inputOnChange', function(){
|
||||
return{
|
||||
restrict: 'A',
|
||||
scope: {},
|
||||
link: function (scope, element, attrs) {
|
||||
var onChangeFunc = scope.$eval(attrs.inputOnChange);
|
||||
element.bind('change', onChangeFunc);
|
||||
|
||||
scope.uploadDown = function () {
|
||||
var file = event.target.files[0];
|
||||
//判断类型是不是图片
|
||||
if (!/image\/\w+/.test(file.type)) {
|
||||
alert("非图片");
|
||||
return;
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = function (e) {
|
||||
alert(this.result);//base64
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
app.directive('loadHead',['$http','config','auth','$location','alertService',function($http,config,auth,$location,alertService){
|
||||
return{
|
||||
restrict: 'A',
|
||||
scope: {},
|
||||
link: function (scope, element, attrs) {
|
||||
element.bind('change', function(){
|
||||
var file = event.target.files[0];
|
||||
//判断类型是不是图片
|
||||
if (!/image\/\w+/.test(file.type)) {
|
||||
alert("非图片");
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = function (e) {
|
||||
alert(this.result);//base64
|
||||
|
||||
$http.post(config.apiUrl + "users/upload_head",
|
||||
{token: auth.token(),imgdata:this.result}
|
||||
).then(function (response) {
|
||||
if(response.data.status == 0){
|
||||
scope.$parent.alertService_1.showMessage('提示',"上传成功",function(){
|
||||
scope.$parent.user = null;
|
||||
scope.$parent.getuserinfo();
|
||||
});
|
||||
}
|
||||
else{
|
||||
scope.$parent.alertService_1.showMessage('提示',"上传失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}]);
|
|
@ -51,6 +51,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
|
|||
.when('/review_project_member', makeRoute('review_project_member.html', 'ReviewProjectMemberController'))
|
||||
.when('/project_publishnote', makeRoute('project_publishnote.html', 'ProjectPublishNoteController'))
|
||||
.when('/login_tip', makeRoute('login_tip.html', 'LoginTipController'))
|
||||
.when('/edit_userinfo', makeRoute('edit_userinfo.html', 'EditUserInfoController'))
|
||||
.otherwise({
|
||||
redirectTo: '/activites'
|
||||
});
|
||||
|
|
|
@ -258,3 +258,12 @@ a.underline {text-decoration:underline;}
|
|||
/*发布帖子,通知*/
|
||||
.full-width-wrap {padding:5px 15px; background-color:#fff; border-top:1px solid #ddd; border-bottom:1px solid #ddd;}
|
||||
.full-width-textarea {width:100%; height:180px; line-height:18px; max-height:180px; border:none; resize:none; font-size:13px; color:#555; overflow-y:auto;}
|
||||
|
||||
/*资料修改*/
|
||||
.blank-row {width:100%; height:38px; line-height:38px; vertical-align:middle;}
|
||||
.upload-input-container {width:30px; height:30px; border:1px solid #ddd; position:relative;}
|
||||
.upload-input {width:30px; height:30px; position:absolute; z-index:1; opacity:0;}
|
||||
.upload-input-container:after {content:" "; position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); background-color:#ddd; background-image:url(../images/male.jpg); width:30px; height:30px; background-size:30px 30px; border-radius:50%;}
|
||||
.select-container {position:relative; padding-left:62px;}
|
||||
.select-text {position:absolute; left:15px;}
|
||||
.select-model {width:100%; border:none; color:#999; margin-top:8px;}
|
Loading…
Reference in New Issue