Showing
9 changed files
with
164 additions
and
49 deletions
@@ -12,12 +12,12 @@ const accountModel = require('../models/account'); | @@ -12,12 +12,12 @@ const accountModel = require('../models/account'); | ||
12 | const passportHelper = require('../../passport/models/passport-helper'); | 12 | const passportHelper = require('../../passport/models/passport-helper'); |
13 | const Promise = require('bluebird'); | 13 | const Promise = require('bluebird'); |
14 | const co = Promise.coroutine; | 14 | const co = Promise.coroutine; |
15 | - | ||
16 | - | 15 | +var fs = require('fs'); |
16 | +var path = require('path'); | ||
17 | +const uuid = require('uuid'); | ||
18 | +const os = require('os'); | ||
17 | const captchaUrl = helpers.urlFormat('/passport/images', {t: Date.now()}); | 19 | const captchaUrl = helpers.urlFormat('/passport/images', {t: Date.now()}); |
18 | 20 | ||
19 | -// const captchaUrl = 'http://localhost:6003/passport/images?t=' + new Date().getTime(); | ||
20 | - | ||
21 | // 根据type获取标题 | 21 | // 根据type获取标题 |
22 | const _getTitle = (type)=> { | 22 | const _getTitle = (type)=> { |
23 | let typeName; | 23 | let typeName; |
@@ -73,7 +73,7 @@ const _getTitle = (type)=> { | @@ -73,7 +73,7 @@ const _getTitle = (type)=> { | ||
73 | * 个人设置页面加载 | 73 | * 个人设置页面加载 |
74 | */ | 74 | */ |
75 | const index = (req, res, next) => { | 75 | const index = (req, res, next) => { |
76 | - let uid = req.user.uid; | 76 | + let uid = req.user.uid || '8041246'; |
77 | 77 | ||
78 | settingModel.getUserInfo(uid).then(result=> { | 78 | settingModel.getUserInfo(uid).then(result=> { |
79 | result.info.gender ? result.genders[result.info.gender - 1].checked = true : | 79 | result.info.gender ? result.genders[result.info.gender - 1].checked = true : |
@@ -82,6 +82,7 @@ const index = (req, res, next) => { | @@ -82,6 +82,7 @@ const index = (req, res, next) => { | ||
82 | result.info.mobile = result.info.mobile ? | 82 | result.info.mobile = result.info.mobile ? |
83 | result.info.mobile.substring(0, 3) + '****' + result.info.mobile.substring(7, 11) : ''; | 83 | result.info.mobile.substring(0, 3) + '****' + result.info.mobile.substring(7, 11) : ''; |
84 | result.stepUrl = '/me/setting/step1'; | 84 | result.stepUrl = '/me/setting/step1'; |
85 | + | ||
85 | res.display('index', { | 86 | res.display('index', { |
86 | module: 'me', | 87 | module: 'me', |
87 | page: 'setting', | 88 | page: 'setting', |
@@ -343,6 +344,40 @@ const validate2 = (req, res)=> { | @@ -343,6 +344,40 @@ const validate2 = (req, res)=> { | ||
343 | })(); | 344 | })(); |
344 | }; | 345 | }; |
345 | 346 | ||
347 | + | ||
348 | +/** | ||
349 | + * 文件处理中间件 | ||
350 | + * @param req | ||
351 | + * @param res | ||
352 | + * @param next | ||
353 | + */ | ||
354 | +function getfilePath(req, res, next) { | ||
355 | + const fid = uuid.v4(); | ||
356 | + const filePath = path.join(os.tmpdir(), fid); | ||
357 | + const uploadStream = fs.createWriteStream(filePath); | ||
358 | + | ||
359 | + req.filePath = filePath; | ||
360 | + req.pipe(uploadStream); | ||
361 | + uploadStream.on('finish', function() { | ||
362 | + next(); | ||
363 | + }); | ||
364 | +} | ||
365 | + | ||
366 | +/** | ||
367 | + * 修改头像 | ||
368 | + * @param req | ||
369 | + * @param res | ||
370 | + */ | ||
371 | +const modifyHead = (req, res)=> { | ||
372 | + let uid = req.user.uid || '8041246'; | ||
373 | + let bucket = 'yhb-head'; | ||
374 | + let filePath = req.filePath; | ||
375 | + | ||
376 | + settingModel.modifyHead(uid, bucket, filePath).then(result=> { | ||
377 | + res.send(result); | ||
378 | + }); | ||
379 | +}; | ||
380 | + | ||
346 | module.exports = { | 381 | module.exports = { |
347 | index, | 382 | index, |
348 | editUserInfo, | 383 | editUserInfo, |
@@ -352,5 +387,7 @@ module.exports = { | @@ -352,5 +387,7 @@ module.exports = { | ||
352 | edit, | 387 | edit, |
353 | success, | 388 | success, |
354 | validate1, | 389 | validate1, |
355 | - validate2 | 390 | + validate2, |
391 | + getfilePath, | ||
392 | + modifyHead | ||
356 | }; | 393 | }; |
@@ -9,6 +9,7 @@ var express = require('express'), | @@ -9,6 +9,7 @@ var express = require('express'), | ||
9 | path = require('path'), | 9 | path = require('path'), |
10 | hbs = require('express-handlebars'); | 10 | hbs = require('express-handlebars'); |
11 | 11 | ||
12 | + | ||
12 | var app = express(); | 13 | var app = express(); |
13 | 14 | ||
14 | // set view engin | 15 | // set view engin |
@@ -28,6 +29,7 @@ app.engine('.hbs', hbs({ | @@ -28,6 +29,7 @@ app.engine('.hbs', hbs({ | ||
28 | helpers: global.yoho.helpers | 29 | helpers: global.yoho.helpers |
29 | })); | 30 | })); |
30 | 31 | ||
32 | + | ||
31 | // router | 33 | // router |
32 | app.use(require('./router')); | 34 | app.use(require('./router')); |
33 | 35 |
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | 8 | ||
9 | const api = global.yoho.API; | 9 | const api = global.yoho.API; |
10 | const crypto = require('crypto'); | 10 | const crypto = require('crypto'); |
11 | +const fs = require('fs'); | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * 查询个人详细信息 | 14 | * 查询个人详细信息 |
@@ -76,11 +77,11 @@ const getUserInfo = (uid) => { | @@ -76,11 +77,11 @@ const getUserInfo = (uid) => { | ||
76 | }; | 77 | }; |
77 | 78 | ||
78 | /* const getVerifyInfo = (uid)=> { | 79 | /* const getVerifyInfo = (uid)=> { |
79 | - return api.get('', { | ||
80 | - method: 'web.passport.getUserVerifyInfo', | ||
81 | - uid: uid | ||
82 | - }).then(result => result); | ||
83 | -};*/ | 80 | + return api.get('', { |
81 | + method: 'web.passport.getUserVerifyInfo', | ||
82 | + uid: uid | ||
83 | + }).then(result => result); | ||
84 | + };*/ | ||
84 | 85 | ||
85 | /** | 86 | /** |
86 | * 编辑个人详细信息 | 87 | * 编辑个人详细信息 |
@@ -179,9 +180,27 @@ const decipheriv = (data) => { | @@ -179,9 +180,27 @@ const decipheriv = (data) => { | ||
179 | return decipherChunks.join(''); | 180 | return decipherChunks.join(''); |
180 | }; | 181 | }; |
181 | 182 | ||
183 | +/** | ||
184 | + * 上传头像 | ||
185 | + * @param uid | ||
186 | + * @param bucket | ||
187 | + * @param fileData | ||
188 | + */ | ||
189 | +const modifyHead = (uid, bucket, fileData)=> { | ||
190 | + return api.postFile('', { | ||
191 | + method: 'app.passport.modifyHead', | ||
192 | + uid: uid, | ||
193 | + bucket: bucket | ||
194 | + }, { | ||
195 | + file_data: fs.createReadStream(fileData) | ||
196 | + }); | ||
197 | +}; | ||
198 | + | ||
199 | + | ||
182 | module.exports = { | 200 | module.exports = { |
183 | getUserInfo: getUserInfo, | 201 | getUserInfo: getUserInfo, |
184 | editUserInfo: editUserInfo, | 202 | editUserInfo: editUserInfo, |
185 | cipheriv: cipheriv, | 203 | cipheriv: cipheriv, |
186 | - decipheriv: decipheriv | 204 | + decipheriv: decipheriv, |
205 | + modifyHead: modifyHead | ||
187 | }; | 206 | }; |
@@ -10,7 +10,6 @@ const router = require('express').Router(); // eslint-disable-line | @@ -10,7 +10,6 @@ const router = require('express').Router(); // eslint-disable-line | ||
10 | const cRoot = './controllers'; | 10 | const cRoot = './controllers'; |
11 | const auth = require(`${global.middleware}/auth`); | 11 | const auth = require(`${global.middleware}/auth`); |
12 | 12 | ||
13 | -// const auth = require(`${global.middleware}/auth`); | ||
14 | 13 | ||
15 | // 订单 | 14 | // 订单 |
16 | const order = require(`${cRoot}/order`); | 15 | const order = require(`${cRoot}/order`); |
@@ -77,6 +76,8 @@ router.post('/setting/step2/:type', auth, setting.validate2); | @@ -77,6 +76,8 @@ router.post('/setting/step2/:type', auth, setting.validate2); | ||
77 | // 第三步 | 76 | // 第三步 |
78 | router.get('/setting/step3/:type', auth, setting.success); | 77 | router.get('/setting/step3/:type', auth, setting.success); |
79 | 78 | ||
79 | +router.post('/setting/modifyHead', auth, setting.getfilePath, setting.modifyHead); | ||
80 | + | ||
80 | router.post('/account/changePwd', auth, account.changePwd); | 81 | router.post('/account/changePwd', auth, account.changePwd); |
81 | router.post('/account/sendMobileMsg', auth, account.sendMobileMsg); | 82 | router.post('/account/sendMobileMsg', auth, account.sendMobileMsg); |
82 | router.post('/account/checkVerifyMsg', auth, account.checkVerifyMsg); | 83 | router.post('/account/checkVerifyMsg', auth, account.checkVerifyMsg); |
@@ -84,7 +85,6 @@ router.post('/account/sendVerifyEmail', auth, account.sendVerifyEmail); | @@ -84,7 +85,6 @@ router.post('/account/sendVerifyEmail', auth, account.sendVerifyEmail); | ||
84 | router.post('/account/checkVerifyMobile', auth, account.checkVerifyMobile); | 85 | router.post('/account/checkVerifyMobile', auth, account.checkVerifyMobile); |
85 | 86 | ||
86 | 87 | ||
87 | - | ||
88 | // 我的收藏 | 88 | // 我的收藏 |
89 | router.get('/collection', auth, favorite.goods); | 89 | router.get('/collection', auth, favorite.goods); |
90 | router.get('/collection/brand', auth, favorite.brand); | 90 | router.get('/collection/brand', auth, favorite.brand); |
@@ -40,18 +40,16 @@ | @@ -40,18 +40,16 @@ | ||
40 | <a class="blue operation" href="{{stepUrl}}/bindMobile">绑定</a> | 40 | <a class="blue operation" href="{{stepUrl}}/bindMobile">绑定</a> |
41 | {{/if}} | 41 | {{/if}} |
42 | </div> | 42 | </div> |
43 | - <!-- <div class="form-group"> | 43 | + <div class="form-group"> |
44 | <label class="label-name">邮箱:</label> | 44 | <label class="label-name">邮箱:</label> |
45 | {{#if info.verify_email}} | 45 | {{#if info.verify_email}} |
46 | <input class="input no-edit" value="{{info.mobile}}"> | 46 | <input class="input no-edit" value="{{info.mobile}}"> |
47 | - <!–<a class="blue operation" href="{{stepUrl}}/modifyEmail">修改</a>–> | ||
48 | - <a class="blue operation">修改</a> | 47 | + <!--<a class="blue operation" href="{{stepUrl}}/modifyEmail">修改</a>--> |
49 | {{else}} | 48 | {{else}} |
50 | <input class="input" type="text" placeholder="请绑定邮箱" disabled> | 49 | <input class="input" type="text" placeholder="请绑定邮箱" disabled> |
51 | - <!–<a class="blue operation" href="{{stepUrl}}/bindEmail">绑定</a>–> | ||
52 | - <a class="blue operation">绑定</a> | 50 | + <!--<a class="blue operation" href="{{stepUrl}}/bindEmail">绑定</a>--> |
53 | {{/if}} | 51 | {{/if}} |
54 | - </div>--> | 52 | + </div> |
55 | <div class="form-group"> | 53 | <div class="form-group"> |
56 | <label class="label-name">出生日期:</label> | 54 | <label class="label-name">出生日期:</label> |
57 | <input id="birthday" class="input" type="text" value="{{info.birthday}}"> | 55 | <input id="birthday" class="input" type="text" value="{{info.birthday}}"> |
@@ -73,7 +71,8 @@ | @@ -73,7 +71,8 @@ | ||
73 | </div> | 71 | </div> |
74 | <div class="user-icon inline-block"> | 72 | <div class="user-icon inline-block"> |
75 | {{#if info.head_ico}} | 73 | {{#if info.head_ico}} |
76 | - <img src="{{info.head_ico}}"> | 74 | + <div class="show-ico"><img src="{{info.head_ico}}"></div> |
75 | + <div class="edit-ico hide"></div> | ||
77 | {{else}} | 76 | {{else}} |
78 | <div class="show-ico"></div> | 77 | <div class="show-ico"></div> |
79 | <div class="edit-ico hide"></div> | 78 | <div class="edit-ico hide"></div> |
@@ -61,7 +61,7 @@ | @@ -61,7 +61,7 @@ | ||
61 | "uuid": "^2.0.2", | 61 | "uuid": "^2.0.2", |
62 | "winston": "^2.2.0", | 62 | "winston": "^2.2.0", |
63 | "winston-daily-rotate-file": "^1.1.4", | 63 | "winston-daily-rotate-file": "^1.1.4", |
64 | - "yoho-node-lib": "0.0.23" | 64 | + "yoho-node-lib": "0.0.28" |
65 | }, | 65 | }, |
66 | "devDependencies": { | 66 | "devDependencies": { |
67 | "autoprefixer": "^6.3.6", | 67 | "autoprefixer": "^6.3.6", |
public/img/me/head.swf
0 → 100644
No preview for this file type
@@ -7,23 +7,20 @@ var cascadingAddress = require('../plugins/cascading-address'); | @@ -7,23 +7,20 @@ var cascadingAddress = require('../plugins/cascading-address'); | ||
7 | var dialog = require('../plugins/dialog'); | 7 | var dialog = require('../plugins/dialog'); |
8 | var _dialog = dialog.Dialog; | 8 | var _dialog = dialog.Dialog; |
9 | var _alert = dialog.Alert; | 9 | var _alert = dialog.Alert; |
10 | +var modifyHead = require('./setting/modifyHead'); | ||
11 | +var tip; | ||
12 | + | ||
13 | +var headHtml = modifyHead.swfobject('head', '600px', '400px', '../../img/me/head.swf?code=' + Math.random() + | ||
14 | + '&upload_url=' + encodeURIComponent(location.protocol + '//' + | ||
15 | + location.hostname + ':' + location.port + '/me/setting/modifyHead')); | ||
10 | 16 | ||
11 | var Bll = { | 17 | var Bll = { |
12 | setIcon: function() { | 18 | setIcon: function() { |
13 | var html = []; | 19 | var html = []; |
14 | 20 | ||
15 | - html.push('<form id="upload_form" method="post" action="" onsubmit="return checkForm()">'); | ||
16 | - html.push('<div class="post-picture inline-block">'); | ||
17 | - html.push('<div class="choose-avatar"></div>'); | ||
18 | - html.push('<div class="post-file"><input id="avatar" name="avatar" type="file" value="点击上传"></div>'); | ||
19 | - html.push('<p class="post-limit">支持JPG、GIF、PNG、JPEG、BMP格式,文件小于3M</p>'); | ||
20 | - html.push('</div>'); | ||
21 | - html.push(' <div class="show-picture inline-block" ><img id="post-picture">'); | ||
22 | - html.push(' </div>'); | ||
23 | - html.push('<div class="preview-picture inline-block">'); | ||
24 | - html.push('<div class="small-preview"></div>'); | 21 | + html.push('<div style="width: 600px;height: 400px">'); |
22 | + html.push(headHtml); | ||
25 | html.push('</div>'); | 23 | html.push('</div>'); |
26 | - html.push('</form>'); | ||
27 | 24 | ||
28 | return html.join(''); | 25 | return html.join(''); |
29 | }, | 26 | }, |
@@ -63,9 +60,8 @@ $('.user-icon').hover(function() { | @@ -63,9 +60,8 @@ $('.user-icon').hover(function() { | ||
63 | 60 | ||
64 | // 编辑头像打开弹框 | 61 | // 编辑头像打开弹框 |
65 | $(document).on('click', '.edit-ico', function() { | 62 | $(document).on('click', '.edit-ico', function() { |
66 | - var tip = new _dialog({ | 63 | + tip = new _dialog({ |
67 | className: 'settled-success', | 64 | className: 'settled-success', |
68 | - title: '自定义头像', | ||
69 | content: Bll.setIcon(), | 65 | content: Bll.setIcon(), |
70 | btns: [ | 66 | btns: [ |
71 | { | 67 | { |
@@ -73,7 +69,7 @@ $(document).on('click', '.edit-ico', function() { | @@ -73,7 +69,7 @@ $(document).on('click', '.edit-ico', function() { | ||
73 | btnClass: ['apply'], | 69 | btnClass: ['apply'], |
74 | name: '保存', | 70 | name: '保存', |
75 | cb: function() { | 71 | cb: function() { |
76 | - tip.close(); | 72 | + modifyHead.uploadImage(); |
77 | } | 73 | } |
78 | }, | 74 | }, |
79 | { | 75 | { |
@@ -88,19 +84,21 @@ $(document).on('click', '.edit-ico', function() { | @@ -88,19 +84,21 @@ $(document).on('click', '.edit-ico', function() { | ||
88 | }).show(); | 84 | }).show(); |
89 | }); | 85 | }); |
90 | 86 | ||
91 | - | ||
92 | -$(document).on('change', '#avatar', function() { | ||
93 | - /* var oFile = $("#avatar")[0].files[0]; | ||
94 | - var oImage = document.getElementById('post-picture'); | ||
95 | - var oReader = new FileReader(); | ||
96 | - oReader.onload = function (e) { | ||
97 | - oImage.src = e.target.result; | ||
98 | - $(".post-picture").hide(); | ||
99 | - $("#post-picture").show(); | ||
100 | - }; | ||
101 | - oReader.readAsDataURL(oFile);*/ | ||
102 | -}); | ||
103 | - | 87 | +/** |
88 | + * 头像上传处理 | ||
89 | + * @param obj | ||
90 | + */ | ||
91 | +window.receive_image_bytes = function(obj) { | ||
92 | + var result = JSON.parse(obj); | ||
93 | + | ||
94 | + if (result.code === 200) { | ||
95 | + tip.close(); | ||
96 | + $('.show-ico img').attr('src', result.data.image_url.split('?')[0]); | ||
97 | + } else { | ||
98 | + tip.close(); | ||
99 | + new _alert('头像修改失败!').show(); | ||
100 | + } | ||
101 | +}; | ||
104 | 102 | ||
105 | $(function() { | 103 | $(function() { |
106 | var address = cascadingAddress({el: '#address'}); | 104 | var address = cascadingAddress({el: '#address'}); |
public/js/me/setting/modifyHead.js
0 → 100644
1 | +/** | ||
2 | + * [个人中心]个人设置-编辑头像中flash相关操作 | ||
3 | + * @author: jiangmin | ||
4 | + * @date: 2016/07/14 | ||
5 | + */ | ||
6 | + | ||
7 | +/** | ||
8 | + * 设置flash样式,并返回html | ||
9 | + * @param id | ||
10 | + * @param width | ||
11 | + * @param height | ||
12 | + * @param url | ||
13 | + * @returns {string} | ||
14 | + */ | ||
15 | +function swfobject(id, width, height, url) { | ||
16 | + var _html = '<object id="' + id + '" width="' + width + '" height="' + height + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">' + | ||
17 | + '<param value="' + url + '" name="movie"> ' + | ||
18 | + '<param value="high" name="quality"> ' + | ||
19 | + '<param value="#E0E0E0" name="bgcolor"> ' + | ||
20 | + '<param name="allowFullScreen" value="true"> ' + | ||
21 | + '<param value="always" name="allowScriptAccess"> ' + | ||
22 | + '<param value="transparent" name="wmode"> ' + | ||
23 | + '<embed width="' + width + '" height="' + height + '" name="' + id + '" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" loop="false" play="true" bgcolor="#E0E0E0" quality="high" wmode="transparent" name="vMessage" src="' + url + '"> ' + | ||
24 | + '</object>'; | ||
25 | + | ||
26 | + return _html; | ||
27 | + | ||
28 | +} | ||
29 | + | ||
30 | +function getFlashMovieObject(movieName) { | ||
31 | + if (window.document[movieName]) { | ||
32 | + return window.document[movieName]; | ||
33 | + } | ||
34 | + if (navigator.appName.indexOf('Microsoft Internet') === -1) { | ||
35 | + if (document.embeds && document.embeds[movieName]) { | ||
36 | + return document.embeds[movieName]; | ||
37 | + } | ||
38 | + } else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1) | ||
39 | + return document.getElementById(movieName); | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +/** | ||
44 | + * 上传图片,点击确定时调用 | ||
45 | + */ | ||
46 | +function uploadImage() { | ||
47 | + var viFlash = getFlashMovieObject('head'); | ||
48 | + | ||
49 | + viFlash.upload_image(); | ||
50 | +} | ||
51 | + | ||
52 | + | ||
53 | +module.exports = { | ||
54 | + swfobject, | ||
55 | + uploadImage | ||
56 | +}; | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + |
-
Please register or login to post a comment