Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
徐炜
9 years ago
Commit
bf1fb2e677648f49b994a3f892e5866c88ba6d51
1 parent
ef6be3a5
https
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
463 additions
and
462 deletions
apps/me/controllers/setting.js
apps/me/controllers/setting.js
View file @
bf1fb2e
/**
* [个人中心]个人设置
* @author: jiangmin
* @date: 2016/07/13
*/
'use strict'
;
const
mcHandler
=
require
(
'../models/menu-crumb-handler'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
config
=
global
.
yoho
.
config
;
const
settingModel
=
require
(
'../models/setting'
);
const
accountModel
=
require
(
'../models/account'
);
const
passportHelper
=
require
(
'../../passport/models/passport-helper'
);
const
Promise
=
require
(
'bluebird'
);
const
co
=
Promise
.
coroutine
;
var
fs
=
require
(
'fs'
);
var
path
=
require
(
'path'
);
const
uuid
=
require
(
'uuid'
);
const
os
=
require
(
'os'
);
const
_
=
require
(
'lodash'
);
const
regMobile
=
/
(\d{3})\d{4}(\d{4})
/
;
// 正则匹配替换手机号码中间4位
const
regEmail
=
/
(\d{3})\d{4}
/
;
// 正则匹配替换邮箱中间4位
const
captchaUrl
=
helpers
.
urlFormat
(
'/passport/images'
,
{
t
:
Date
.
now
()
});
// 根据type获取标题
const
_getTitle
=
(
type
)
=>
{
let
typeName
;
let
proName
;
let
isModifyMobile
=
false
;
let
isBindMobile
=
false
;
let
isModifyEmail
=
false
;
let
isBindEmail
=
false
;
let
isShowPassword
=
false
;
switch
(
type
)
{
case
'modifyPassword'
:
typeName
=
'修改密码'
;
proName
=
'输入新密码'
;
isShowPassword
=
true
;
break
;
case
'modifyMobile'
:
typeName
=
'修改手机号码'
;
proName
=
'绑定手机'
;
isModifyMobile
=
true
;
break
;
case
'bindMobile'
:
typeName
=
'绑定手机号码'
;
proName
=
'绑定手机'
;
isBindMobile
=
true
;
break
;
case
'modifyEmail'
:
typeName
=
'修改邮箱'
;
proName
=
'绑定邮箱'
;
isModifyEmail
=
true
;
break
;
case
'bindEmail'
:
typeName
=
'绑定邮箱'
;
proName
=
'绑定邮箱'
;
isBindEmail
=
true
;
break
;
default
:
typeName
=
''
;
break
;
}
return
{
typeName
:
typeName
,
proName
:
proName
,
isModifyMobile
,
isBindMobile
,
isModifyEmail
,
isBindEmail
,
isShowPassword
};
};
const
cookieHelper
=
{
setVal
(
res
,
k
,
v
,
ops
)
{
res
.
cookie
(
k
,
v
,
Object
.
assign
({
domain
:
config
.
cookieDomain
,
httpOnly
:
true
},
ops
));
},
getVal
(
req
,
k
)
{
return
req
.
cookies
[
k
];
}
}
/**
* 个人设置页面加载
*/
const
index
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
Promise
.
all
([
settingModel
.
getUserInfo
(
uid
),
mcHandler
.
getMeThumb
()]).
then
(
result
=>
{
const
thumb
=
result
[
1
];
let
user
=
result
[
0
];
user
.
info
.
gender
?
user
.
genders
[
user
.
info
.
gender
-
1
].
checked
=
true
:
user
.
genders
[
2
].
checked
=
true
;
user
.
info
.
head_ico
=
user
.
info
.
head_ico
?
helpers
.
image
(
user
.
info
.
head_ico
,
400
,
300
,
2
)
:
''
;
user
.
info
.
mobile
=
user
.
info
.
mobile
?
user
.
info
.
mobile
.
replace
(
regMobile
,
'$1****$2'
)
:
''
;
user
.
stepUrl
=
'/me/setting/step1'
;
if
(
user
.
info
.
birthday
)
{
let
a
=
user
.
info
.
birthday
.
split
(
'-'
);
_
.
forEach
(
user
.
date
.
selectYear
,
function
(
x
)
{
if
(
x
.
value
===
a
[
0
])
{
x
.
isSelected
=
'selected'
;
}
});
_
.
forEach
(
user
.
date
.
selectMonth
,
function
(
x
)
{
if
(
parseInt
(
x
.
value
,
10
)
===
parseInt
(
a
[
1
],
10
))
{
x
.
isSelected
=
'selected'
;
}
});
_
.
forEach
(
user
.
date
.
selectDay
,
function
(
x
)
{
if
(
parseInt
(
x
.
value
,
10
)
===
parseInt
(
a
[
2
],
10
))
{
x
.
isSelected
=
'selected'
;
}
});
}
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
setting
:
true
,
title
:
'个人设置'
,
userInfo
:
user
,
_token
:
req
.
csrfToken
()
}
});
}).
catch
(
next
);
};
/**
* 编辑信息
* @param req
* @param res
* @param next
*/
const
editUserInfo
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
query
=
req
.
body
;
settingModel
.
editUserInfo
(
uid
,
query
).
then
(
result
=>
{
res
.
send
(
result
);
}).
catch
(
next
);
};
/*
* step1 绑定的手机号码身份验证
* */
const
bindMobile
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
type
=
req
.
params
.
type
;
settingModel
.
getUserInfo
(
uid
).
then
(
result
=>
{
if
(
result
.
info
.
verify_mobile
!==
''
)
{
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
let
info
=
result
.
info
;
info
.
ellipsisMobile
=
info
.
verify_mobile
.
replace
(
regMobile
,
'$1****$2'
);
info
.
checkCode
=
req
.
csrfToken
();
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
region
:
passportHelper
.
getCountry
(),
location
:
'+86'
,
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
validateStep
:
true
,
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
captchaUrl
:
captchaUrl
,
isShowMobile
:
true
,
data
:
info
}
});
});
}
next
();
});
};
/**
* step1 绑定的邮箱进行身份验证
*/
const
bindEmail
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
type
=
req
.
params
.
type
;
settingModel
.
getUserInfo
(
uid
).
then
(
result
=>
{
if
(
result
.
info
.
verify_email
!==
''
)
{
let
info
=
result
.
info
;
info
.
ellipsisEmail
=
info
.
verify_email
.
replace
(
regEmail
,
'$1****'
);
info
.
checkCode
=
req
.
csrfToken
();
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
validateStep
:
true
,
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
captchaUrl
:
captchaUrl
,
isShowEmail
:
true
,
data
:
info
}
});
});
}
next
();
});
};
/**
*step1 登录密码进行身份验证
*/
const
modifyType
=
(
req
,
res
)
=>
{
let
type
=
req
.
params
.
type
;
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
validateStep
:
true
,
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
captchaUrl
:
captchaUrl
,
isShowPassword
:
true
,
checkCode
:
req
.
csrfToken
()
}
});
});
};
/*
* step2 操作界面-渲染页面
* */
const
edit
=
(
req
,
res
)
=>
{
let
type
=
req
.
params
.
type
;
if
(
Number
(
cookieHelper
.
getVal
(
req
,
type
+
"_STEP"
))
!==
1
)
{
res
.
redirect
(
helpers
.
urlFormat
(
'/me/setting/step1/'
+
type
));
return
;
}
let
result
=
{
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
isShowMobile
:
_getTitle
(
type
).
isModifyMobile
||
_getTitle
(
type
).
isBindMobile
,
isShowEmail
:
_getTitle
(
type
).
isModifyEmail
||
_getTitle
(
type
).
isBindEmail
,
isShowPassword
:
_getTitle
(
type
).
isShowPassword
};
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
Object
.
assign
({
region
:
passportHelper
.
getCountry
(),
location
:
'+86'
,
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
operateStep
:
true
,
stepUrl
:
'/me/setting/step3/'
+
type
,
captchaUrl
:
captchaUrl
,
checkCode
:
req
.
csrfToken
()
},
result
)
});
});
};
/*
* step3 操作成功-渲染界面
* */
const
success
=
(
req
,
res
)
=>
{
let
type
=
req
.
params
.
type
;
let
step
=
Number
(
cookieHelper
.
getVal
(
req
,
type
+
"_STEP"
))
||
0
;
if
(
step
!==
2
)
{
res
.
redirect
(
helpers
.
urlFormat
(
'/me/setting/step'
+
(
step
+
1
)
+
'/'
+
type
));
return
;
}
cookieHelper
.
setVal
(
res
,
type
+
"_STEP"
,
0
,
{
maxAge
:
-
1
});
let
result
=
{
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
isModifyMobile
:
_getTitle
(
type
).
isModifyMobile
,
isBindMobile
:
_getTitle
(
type
).
isBindMobile
,
isModifyEmail
:
_getTitle
(
type
).
isModifyEmail
,
isBindEmail
:
_getTitle
(
type
).
isBindEmail
,
isShowPassword
:
_getTitle
(
type
).
isShowPassword
};
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
Object
.
assign
({
region
:
passportHelper
.
getCountry
(),
location
:
'+86'
,
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
successStep
:
true
,
captchaUrl
:
captchaUrl
},
result
)
});
});
};
/*
* post1 第一步身份验证的post请求
* */
const
validate1
=
(
req
,
res
)
=>
{
co
(
function
*
()
{
let
type
=
req
.
params
.
type
;
let
uid
=
req
.
user
.
uid
;
let
body
=
req
.
body
;
let
a
;
if
(
type
===
'password'
)
{
a
=
yield
accountModel
.
verifyPwd
(
uid
,
body
.
password
);
}
else
if
(
type
===
'mobile'
)
{
a
=
yield
accountModel
.
checkVerifyMsg
(
body
.
code
,
body
.
mobile
,
body
.
area
);
}
else
if
(
type
===
'email'
)
{
a
=
yield
accountModel
.
sendVerifyEmail
(
uid
,
body
.
email
);
}
if
(
a
)
{
cookieHelper
.
setVal
(
res
,
req
.
body
.
type
+
"_STEP"
,
1
);
res
.
send
(
a
);
}
})();
};
/*
* post2 第二步具体操作的post请求
* */
const
validate2
=
(
req
,
res
)
=>
{
co
(
function
*
()
{
let
type
=
req
.
params
.
type
;
let
uid
=
req
.
user
.
uid
;
let
body
=
req
.
body
;
if
(
type
===
'password'
)
{
let
a
=
yield
accountModel
.
changePwd
(
uid
,
body
.
password
);
if
(
a
.
code
===
200
)
{
cookieHelper
.
setVal
(
res
,
body
.
type
+
"_STEP"
,
2
);
res
.
send
(
a
);
}
}
else
if
(
type
===
'mobile'
)
{
let
a
=
yield
accountModel
.
checkVerifyMsg
(
body
.
code
,
body
.
mobile
,
body
.
area
);
let
b
=
yield
accountModel
.
modifyVerifyMobile
(
uid
,
body
.
area
,
body
.
mobile
);
if
(
a
.
code
===
200
&&
b
.
code
===
200
)
{
cookieHelper
.
setVal
(
res
,
body
.
type
+
"_STEP"
,
2
);
res
.
send
({
code
:
200
,
data
:
{}
});
}
else
{
let
msg
=
[];
if
(
a
.
code
!==
200
)
{
msg
.
push
(
'<p>图片验证:'
+
a
.
message
+
'</p>'
);
}
if
(
b
.
code
!==
200
)
{
msg
.
push
(
'<p>修改号码:'
+
a
.
message
+
'</p>'
);
}
res
.
send
({
code
:
500
,
message
:
msg
.
join
(
''
)
});
}
}
})();
};
/**
* 文件处理中间件
* @param req
* @param res
* @param next
*/
function
getfilePath
(
req
,
res
,
next
)
{
const
fid
=
uuid
.
v4
();
const
filePath
=
path
.
join
(
os
.
tmpdir
(),
fid
);
const
uploadStream
=
fs
.
createWriteStream
(
filePath
);
req
.
filePath
=
filePath
;
req
.
pipe
(
uploadStream
);
uploadStream
.
on
(
'finish'
,
function
()
{
next
();
});
}
/**
* 修改头像
* @param req
* @param res
*/
const
modifyHead
=
(
req
,
res
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
bucket
=
'yhb-head'
;
let
filePath
=
req
.
filePath
;
settingModel
.
modifyHead
(
uid
,
bucket
,
filePath
).
then
(
result
=>
{
res
.
send
(
result
);
});
};
module
.
exports
=
{
index
,
editUserInfo
,
bindMobile
,
bindEmail
,
modifyType
,
edit
,
success
,
validate1
,
validate2
,
getfilePath
,
modifyHead
};
\ No newline at end of file
/**
* [个人中心]个人设置
* @author: jiangmin
* @date: 2016/07/13
*/
'use strict'
;
const
mcHandler
=
require
(
'../models/menu-crumb-handler'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
config
=
global
.
yoho
.
config
;
const
settingModel
=
require
(
'../models/setting'
);
const
accountModel
=
require
(
'../models/account'
);
const
passportHelper
=
require
(
'../../passport/models/passport-helper'
);
const
Promise
=
require
(
'bluebird'
);
const
co
=
Promise
.
coroutine
;
var
fs
=
require
(
'fs'
);
var
path
=
require
(
'path'
);
const
uuid
=
require
(
'uuid'
);
const
os
=
require
(
'os'
);
const
_
=
require
(
'lodash'
);
const
regMobile
=
/
(\d{3})\d{4}(\d{4})
/
;
// 正则匹配替换手机号码中间4位
const
regEmail
=
/
(\d{3})\d{4}
/
;
// 正则匹配替换邮箱中间4位
const
captchaUrl
=
helpers
.
urlFormat
(
'/passport/images'
,
{
t
:
Date
.
now
()
});
// 根据type获取标题
const
_getTitle
=
(
type
)
=>
{
let
typeName
;
let
proName
;
let
isModifyMobile
=
false
;
let
isBindMobile
=
false
;
let
isModifyEmail
=
false
;
let
isBindEmail
=
false
;
let
isShowPassword
=
false
;
switch
(
type
)
{
case
'modifyPassword'
:
typeName
=
'修改密码'
;
proName
=
'输入新密码'
;
isShowPassword
=
true
;
break
;
case
'modifyMobile'
:
typeName
=
'修改手机号码'
;
proName
=
'绑定手机'
;
isModifyMobile
=
true
;
break
;
case
'bindMobile'
:
typeName
=
'绑定手机号码'
;
proName
=
'绑定手机'
;
isBindMobile
=
true
;
break
;
case
'modifyEmail'
:
typeName
=
'修改邮箱'
;
proName
=
'绑定邮箱'
;
isModifyEmail
=
true
;
break
;
case
'bindEmail'
:
typeName
=
'绑定邮箱'
;
proName
=
'绑定邮箱'
;
isBindEmail
=
true
;
break
;
default
:
typeName
=
''
;
break
;
}
return
{
typeName
:
typeName
,
proName
:
proName
,
isModifyMobile
,
isBindMobile
,
isModifyEmail
,
isBindEmail
,
isShowPassword
};
};
const
cookieHelper
=
{
setVal
(
res
,
k
,
v
,
ops
)
{
res
.
cookie
(
k
,
v
,
Object
.
assign
({
domain
:
config
.
cookieDomain
,
httpOnly
:
true
},
ops
));
},
getVal
(
req
,
k
)
{
return
req
.
cookies
[
k
];
}
}
/**
* 个人设置页面加载
*/
const
index
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
Promise
.
all
([
settingModel
.
getUserInfo
(
uid
),
mcHandler
.
getMeThumb
()]).
then
(
result
=>
{
const
thumb
=
result
[
1
];
let
user
=
result
[
0
];
user
.
info
.
gender
?
user
.
genders
[
user
.
info
.
gender
-
1
].
checked
=
true
:
user
.
genders
[
2
].
checked
=
true
;
user
.
info
.
head_ico
=
user
.
info
.
head_ico
?
helpers
.
image
(
user
.
info
.
head_ico
,
400
,
300
,
2
)
:
''
;
user
.
info
.
mobile
=
user
.
info
.
mobile
?
user
.
info
.
mobile
.
replace
(
regMobile
,
'$1****$2'
)
:
''
;
user
.
stepUrl
=
'/me/setting/step1'
;
if
(
user
.
info
.
birthday
)
{
let
a
=
user
.
info
.
birthday
.
split
(
'-'
);
_
.
forEach
(
user
.
date
.
selectYear
,
function
(
x
)
{
if
(
x
.
value
===
a
[
0
])
{
x
.
isSelected
=
'selected'
;
}
});
_
.
forEach
(
user
.
date
.
selectMonth
,
function
(
x
)
{
if
(
parseInt
(
x
.
value
,
10
)
===
parseInt
(
a
[
1
],
10
))
{
x
.
isSelected
=
'selected'
;
}
});
_
.
forEach
(
user
.
date
.
selectDay
,
function
(
x
)
{
if
(
parseInt
(
x
.
value
,
10
)
===
parseInt
(
a
[
2
],
10
))
{
x
.
isSelected
=
'selected'
;
}
});
}
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
setting
:
true
,
title
:
'个人设置'
,
userInfo
:
user
,
_token
:
req
.
csrfToken
()
}
});
}).
catch
(
next
);
};
/**
* 编辑信息
* @param req
* @param res
* @param next
*/
const
editUserInfo
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
query
=
req
.
body
;
settingModel
.
editUserInfo
(
uid
,
query
).
then
(
result
=>
{
res
.
send
(
result
);
}).
catch
(
next
);
};
/*
* step1 绑定的手机号码身份验证
* */
const
bindMobile
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
type
=
req
.
params
.
type
;
settingModel
.
getUserInfo
(
uid
).
then
(
result
=>
{
if
(
result
.
info
.
verify_mobile
!==
''
)
{
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
let
info
=
result
.
info
;
info
.
ellipsisMobile
=
info
.
verify_mobile
.
replace
(
regMobile
,
'$1****$2'
);
info
.
checkCode
=
req
.
csrfToken
();
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
region
:
passportHelper
.
getCountry
(),
location
:
'+86'
,
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
validateStep
:
true
,
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
captchaUrl
:
captchaUrl
,
isShowMobile
:
true
,
data
:
info
}
});
});
}
next
();
});
};
/**
* step1 绑定的邮箱进行身份验证
*/
const
bindEmail
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
type
=
req
.
params
.
type
;
settingModel
.
getUserInfo
(
uid
).
then
(
result
=>
{
if
(
result
.
info
.
verify_email
!==
''
)
{
let
info
=
result
.
info
;
info
.
ellipsisEmail
=
info
.
verify_email
.
replace
(
regEmail
,
'$1****'
);
info
.
checkCode
=
req
.
csrfToken
();
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
validateStep
:
true
,
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
captchaUrl
:
captchaUrl
,
isShowEmail
:
true
,
data
:
info
}
});
});
}
next
();
});
};
/**
*step1 登录密码进行身份验证
*/
const
modifyType
=
(
req
,
res
)
=>
{
let
type
=
req
.
params
.
type
;
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
{
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
validateStep
:
true
,
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
captchaUrl
:
captchaUrl
,
isShowPassword
:
true
,
checkCode
:
req
.
csrfToken
()
}
});
});
};
/*
* step2 操作界面-渲染页面
* */
const
edit
=
(
req
,
res
)
=>
{
let
type
=
req
.
params
.
type
;
if
(
Number
(
cookieHelper
.
getVal
(
req
,
type
+
"_STEP"
))
!==
1
)
{
res
.
redirect
(
helpers
.
urlFormat
(
'/me/setting/step1/'
+
type
));
return
;
}
let
result
=
{
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
isShowMobile
:
_getTitle
(
type
).
isModifyMobile
||
_getTitle
(
type
).
isBindMobile
,
isShowEmail
:
_getTitle
(
type
).
isModifyEmail
||
_getTitle
(
type
).
isBindEmail
,
isShowPassword
:
_getTitle
(
type
).
isShowPassword
};
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
Object
.
assign
({
region
:
passportHelper
.
getCountry
(),
location
:
'+86'
,
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
operateStep
:
true
,
stepUrl
:
'/me/setting/step3/'
+
type
,
captchaUrl
:
captchaUrl
,
checkCode
:
req
.
csrfToken
()
},
result
)
});
});
};
/*
* step3 操作成功-渲染界面
* */
const
success
=
(
req
,
res
)
=>
{
let
type
=
req
.
params
.
type
;
let
step
=
Number
(
cookieHelper
.
getVal
(
req
,
type
+
"_STEP"
))
||
0
;
if
(
step
!==
2
)
{
res
.
redirect
(
helpers
.
urlFormat
(
'/me/setting/step'
+
(
step
+
1
)
+
'/'
+
type
));
return
;
}
cookieHelper
.
setVal
(
res
,
type
+
"_STEP"
,
0
,
{
maxAge
:
-
1
});
let
result
=
{
title
:
_getTitle
(
type
).
typeName
,
proTitle
:
_getTitle
(
type
).
proName
,
isModifyMobile
:
_getTitle
(
type
).
isModifyMobile
,
isBindMobile
:
_getTitle
(
type
).
isBindMobile
,
isModifyEmail
:
_getTitle
(
type
).
isModifyEmail
,
isBindEmail
:
_getTitle
(
type
).
isBindEmail
,
isShowPassword
:
_getTitle
(
type
).
isShowPassword
};
mcHandler
.
getMeThumb
().
then
((
thumb
)
=>
{
res
.
display
(
'index'
,
{
module
:
'me'
,
page
:
'setting'
,
isMe
:
true
,
content
:
Object
.
assign
({
region
:
passportHelper
.
getCountry
(),
location
:
'+86'
,
nav
:
mcHandler
.
getMeCrumb
(
'个人设置'
),
navigation
:
mcHandler
.
getSideMenu
(
'个人设置'
),
banner
:
thumb
,
successStep
:
true
,
captchaUrl
:
captchaUrl
},
result
)
});
});
};
/*
* post1 第一步身份验证的post请求
* */
const
validate1
=
(
req
,
res
)
=>
{
co
(
function
*
()
{
let
type
=
req
.
params
.
type
;
let
uid
=
req
.
user
.
uid
;
let
body
=
req
.
body
;
let
a
;
if
(
type
===
'password'
)
{
a
=
yield
accountModel
.
verifyPwd
(
uid
,
body
.
password
);
}
else
if
(
type
===
'mobile'
)
{
a
=
yield
accountModel
.
checkVerifyMsg
(
body
.
code
,
body
.
mobile
,
body
.
area
);
}
else
if
(
type
===
'email'
)
{
a
=
yield
accountModel
.
sendVerifyEmail
(
uid
,
body
.
email
);
}
if
(
a
)
{
cookieHelper
.
setVal
(
res
,
req
.
body
.
type
+
"_STEP"
,
1
);
res
.
send
(
a
);
}
})();
};
/*
* post2 第二步具体操作的post请求
* */
const
validate2
=
(
req
,
res
)
=>
{
co
(
function
*
()
{
let
type
=
req
.
params
.
type
;
let
uid
=
req
.
user
.
uid
;
let
body
=
req
.
body
;
if
(
type
===
'password'
)
{
let
a
=
yield
accountModel
.
changePwd
(
uid
,
body
.
password
);
if
(
a
.
code
===
200
)
{
cookieHelper
.
setVal
(
res
,
body
.
type
+
"_STEP"
,
2
);
res
.
send
(
a
);
}
}
else
if
(
type
===
'mobile'
)
{
let
a
=
yield
accountModel
.
checkVerifyMsg
(
body
.
code
,
body
.
mobile
,
body
.
area
);
let
b
=
yield
accountModel
.
modifyVerifyMobile
(
uid
,
body
.
area
,
body
.
mobile
);
if
(
a
.
code
===
200
&&
b
.
code
===
200
)
{
cookieHelper
.
setVal
(
res
,
body
.
type
+
"_STEP"
,
2
);
res
.
send
({
code
:
200
,
data
:
{}
});
}
else
{
let
msg
=
[];
if
(
a
.
code
!==
200
)
{
msg
.
push
(
'<p>图片验证:'
+
a
.
message
+
'</p>'
);
}
if
(
b
.
code
!==
200
)
{
msg
.
push
(
'<p>修改号码:'
+
a
.
message
+
'</p>'
);
}
res
.
send
({
code
:
500
,
message
:
msg
.
join
(
''
)
});
}
}
})();
};
/**
* 文件处理中间件
* @param req
* @param res
* @param next
*/
function
getfilePath
(
req
,
res
,
next
)
{
const
fid
=
uuid
.
v4
();
const
filePath
=
path
.
join
(
os
.
tmpdir
(),
fid
);
const
uploadStream
=
fs
.
createWriteStream
(
filePath
);
req
.
filePath
=
filePath
;
req
.
pipe
(
uploadStream
);
uploadStream
.
on
(
'finish'
,
function
()
{
next
();
});
}
/**
* 修改头像
* @param req
* @param res
*/
const
modifyHead
=
(
req
,
res
)
=>
{
let
uid
=
req
.
user
.
uid
;
let
bucket
=
'yhb-head'
;
let
filePath
=
req
.
filePath
;
settingModel
.
modifyHead
(
uid
,
bucket
,
filePath
).
then
(
result
=>
{
res
.
send
(
result
);
});
};
module
.
exports
=
{
index
,
editUserInfo
,
bindMobile
,
bindEmail
,
modifyType
,
edit
,
success
,
validate1
,
validate2
,
getfilePath
,
modifyHead
};
...
...
Please
register
or
login
to post a comment