diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb
index ed9115382..7989d36d0 100644
--- a/app/api/mobile/apis/users.rb
+++ b/app/api/mobile/apis/users.rb
@@ -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
diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb
index dcdf48d3b..657b1cb7b 100644
--- a/app/api/mobile/entities/user.rb
+++ b/app/api/mobile/entities/user.rb
@@ -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
#签名
diff --git a/app/services/users_service.rb b/app/services/users_service.rb
index c275e20dd..540e1bbff 100644
--- a/app/services/users_service.rb
+++ b/app/services/users_service.rb
@@ -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
diff --git a/public/assets/wechat/edit_userinfo.html b/public/assets/wechat/edit_userinfo.html
new file mode 100644
index 000000000..dcd220a47
--- /dev/null
+++ b/public/assets/wechat/edit_userinfo.html
@@ -0,0 +1,42 @@
+
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/edit_userinfo.js b/public/javascripts/wechat/controllers/edit_userinfo.js
new file mode 100644
index 000000000..2e5b356ad
--- /dev/null
+++ b/public/javascripts/wechat/controllers/edit_userinfo.js
@@ -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);
+ }
+ });
+ };
+
+}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/directives/input_on_change.js b/public/javascripts/wechat/directives/input_on_change.js
deleted file mode 100644
index 43baa3828..000000000
--- a/public/javascripts/wechat/directives/input_on_change.js
+++ /dev/null
@@ -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
- }
- }
-
- }
- }
-});
\ No newline at end of file
diff --git a/public/javascripts/wechat/directives/load_head.js b/public/javascripts/wechat/directives/load_head.js
new file mode 100644
index 000000000..54f464dcb
--- /dev/null
+++ b/public/javascripts/wechat/directives/load_head.js
@@ -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('提示',"上传失败");
+ }
+ });
+ }
+ });
+ }
+ }
+}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js
index 2182e16ee..e5c87d1ab 100644
--- a/public/javascripts/wechat/others/routes.js
+++ b/public/javascripts/wechat/others/routes.js
@@ -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'
});
diff --git a/public/stylesheets/weui/weixin.css b/public/stylesheets/weui/weixin.css
index 3d960b4ad..4e6e27bec 100644
--- a/public/stylesheets/weui/weixin.css
+++ b/public/stylesheets/weui/weixin.css
@@ -257,4 +257,13 @@ 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;}
\ No newline at end of file
+.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;}
\ No newline at end of file