Extract user's profile

This commit is contained in:
syuilo 2017-02-22 12:43:15 +09:00
parent ce216d218b
commit f2c5dc468c
10 changed files with 102 additions and 69 deletions

View file

@ -39,7 +39,7 @@ module.exports = async (params, user, _, isSecure) =>
return rej('too long location'); return rej('too long location');
} }
user.location = location; user.profile.location = location;
} }
// Get 'bio' parameter // Get 'bio' parameter
@ -49,21 +49,19 @@ module.exports = async (params, user, _, isSecure) =>
return rej('too long bio'); return rej('too long bio');
} }
user.bio = bio; user.profile.bio = bio;
} }
// Get 'birthday' parameter // Get 'birthday' parameter
const birthday = params.birthday; const birthday = params.birthday;
if (birthday != null) { if (birthday != null) {
if (birthday != '') { if (!isValidBirthday(birthday)) {
if (!isValidBirthday(birthday)) { return rej('invalid birthday');
return rej('invalid birthday');
}
user.birthday = birthday;
} else {
user.birthday = null;
} }
user.profile.birthday = birthday;
} else {
user.profile.birthday = null;
} }
// Get 'avatar_id' parameter // Get 'avatar_id' parameter
@ -81,11 +79,9 @@ module.exports = async (params, user, _, isSecure) =>
await User.update(user._id, { await User.update(user._id, {
$set: { $set: {
name: user.name, name: user.name,
location: user.location,
bio: user.bio,
birthday: user.birthday,
avatar_id: user.avatar_id, avatar_id: user.avatar_id,
banner_id: user.banner_id banner_id: user.banner_id,
profile: user.profile
} }
}); });

View file

@ -65,14 +65,12 @@ export default async (req: express.Request, res: express.Response) => {
token: secret, token: secret,
avatar_id: null, avatar_id: null,
banner_id: null, banner_id: null,
birthday: null,
created_at: new Date(), created_at: new Date(),
bio: null, description: null,
email: null, email: null,
followers_count: 0, followers_count: 0,
following_count: 0, following_count: 0,
links: null, links: null,
location: null,
name: name, name: name,
password: hash, password: hash,
posts_count: 0, posts_count: 0,
@ -80,7 +78,17 @@ export default async (req: express.Request, res: express.Response) => {
liked_count: 0, liked_count: 0,
drive_capacity: 1073741824, // 1GB drive_capacity: 1073741824, // 1GB
username: username, username: username,
username_lower: username.toLowerCase() username_lower: username.toLowerCase(),
profile: {
bio: null,
birthday: null,
blood: null,
gender: null,
handedness: null,
height: null,
location: null,
weight: null
}
}); });
// Response // Response

View file

@ -1,11 +1,15 @@
<mk-list-user><a class="avatar-anchor" href={ CONFIG.url + '/' + user.username }><img class="avatar" src={ user.avatar_url + '?thumbnail&size=64' } alt="avatar"/></a> <mk-list-user>
<a class="avatar-anchor" href={ CONFIG.url + '/' + user.username }>
<img class="avatar" src={ user.avatar_url + '?thumbnail&size=64' } alt="avatar"/>
</a>
<div class="main"> <div class="main">
<header> <header>
<div class="left"><a class="name" href={ CONFIG.url + '/' + user.username }>{ user.name }</a><span class="username">@{ user.username }</span></div> <a class="name" href={ CONFIG.url + '/' + user.username }>{ user.name }</a>
<span class="username">@{ user.username }</span>
</header> </header>
<div class="body"> <div class="body">
<p class="followed" if={ user.is_followed }>フォローされています</p> <p class="followed" if={ user.is_followed }>フォローされています</p>
<div class="bio">{ user.bio }</div> <div class="description">{ user.description }</div>
</div> </div>
</div> </div>
<mk-follow-button user={ user }></mk-follow-button> <mk-follow-button user={ user }></mk-follow-button>
@ -41,31 +45,23 @@
> header > header
margin-bottom 2px margin-bottom 2px
&:after > .name
content "" display inline
display block margin 0
clear both padding 0
color #777
font-size 1em
font-weight 700
text-align left
text-decoration none
> .left &:hover
float left text-decoration underline
> .name > .username
display inline text-align left
margin 0 margin 0 0 0 8px
padding 0 color #ccc
color #777
font-size 1em
font-weight 700
text-align left
text-decoration none
&:hover
text-decoration underline
> .username
text-align left
margin 0 0 0 8px
color #ccc
> .body > .body
> .followed > .followed
@ -78,7 +74,7 @@
background #eefaff background #eefaff
border-radius 4px border-radius 4px
> .bio > .description
cursor default cursor default
display block display block
margin 0 margin 0

View file

@ -3,7 +3,7 @@
<div class="title"> <div class="title">
<p class="name" href={ CONFIG.url + '/' + user.username }>{ user.name }</p> <p class="name" href={ CONFIG.url + '/' + user.username }>{ user.name }</p>
<p class="username">@{ user.username }</p> <p class="username">@{ user.username }</p>
<p class="location" if={ user.location }><i class="fa fa-map-marker"></i>{ user.location }</p> <p class="location" if={ user.profile.location }><i class="fa fa-map-marker"></i>{ user.profile.location }</p>
</div> </div>
<footer><a href={ '/' + user.username }>投稿</a><a href={ '/' + user.username + '/media' }>メディア</a><a href={ '/' + user.username + '/graphs' }>グラフ</a> <footer><a href={ '/' + user.username }>投稿</a><a href={ '/' + user.username + '/media' }>メディア</a><a href={ '/' + user.username + '/graphs' }>グラフ</a>
<button onclick={ NotImplementedException }><i class="fa fa-ellipsis-h"></i></button> <button onclick={ NotImplementedException }><i class="fa fa-ellipsis-h"></i></button>

View file

@ -5,7 +5,7 @@
<p class="name">{ user.name }</p> <p class="name">{ user.name }</p>
<p class="username">@{ user.username }</p> <p class="username">@{ user.username }</p>
</div> </div>
<div class="bio">{ user.bio }</div> <div class="description">{ user.description }</div>
<div class="status"> <div class="status">
<div> <div>
<p>投稿</p><a>{ user.posts_count }</a> <p>投稿</p><a>{ user.posts_count }</a>
@ -69,7 +69,7 @@
font-size 0.8em font-size 0.8em
color #999 color #999
> .bio > .description
padding 0 16px padding 0 16px
font-size 0.7em font-size 0.7em
color #555 color #555

View file

@ -3,9 +3,9 @@
<mk-big-follow-button user={ user }></mk-big-follow-button> <mk-big-follow-button user={ user }></mk-big-follow-button>
<p class="followed" if={ user.is_followed }>フォローされています</p> <p class="followed" if={ user.is_followed }>フォローされています</p>
</div> </div>
<div class="bio" if={ user.bio != '' }>{ user.bio }</div> <div class="description" if={ user.description }>{ user.description }</div>
<div class="birthday" if={ user.birthday }> <div class="birthday" if={ user.profile.birthday }>
<p><i class="fa fa-birthday-cake"></i>{ user.birthday.replace('-', '年').replace('-', '月') + '日' } ({ age(user.birthday) }歳)</p> <p><i class="fa fa-birthday-cake"></i>{ user.profile.birthday.replace('-', '年').replace('-', '月') + '日' } ({ age(user.profile.birthday) }歳)</p>
</div> </div>
<div class="twitter" if={ user.twitter }> <div class="twitter" if={ user.twitter }>
<p><i class="fa fa-twitter"></i><a href={ 'https://twitter.com/' + user.twitter.screen_name } target="_blank">@{ user.twitter.screen_name }</a></p> <p><i class="fa fa-twitter"></i><a href={ 'https://twitter.com/' + user.twitter.screen_name } target="_blank">@{ user.twitter.screen_name }</a></p>
@ -39,7 +39,7 @@
background #eefaff background #eefaff
border-radius 4px border-radius 4px
> .bio > .description
padding 16px padding 16px
color #555 color #555
border-top solid 1px #eee border-top solid 1px #eee

View file

@ -1,8 +1,14 @@
<mk-user-preview><a class="avatar-anchor" href={ CONFIG.url + '/' + user.username }><img class="avatar" src={ user.avatar_url + '?thumbnail&size=64' } alt="avatar"/></a> <mk-user-preview>
<a class="avatar-anchor" href={ CONFIG.url + '/' + user.username }>
<img class="avatar" src={ user.avatar_url + '?thumbnail&size=64' } alt="avatar"/>
</a>
<div class="main"> <div class="main">
<header><a class="name" href={ CONFIG.url + '/' + user.username }>{ user.name }</a><span class="username">@{ user.username }</span></header> <header>
<a class="name" href={ CONFIG.url + '/' + user.username }>{ user.name }</a>
<span class="username">@{ user.username }</span>
</header>
<div class="body"> <div class="body">
<div class="bio">{ user.bio }</div> <div class="description">{ user.description }</div>
</div> </div>
</div> </div>
<style> <style>
@ -75,7 +81,7 @@
> .body > .body
> .bio > .description
cursor default cursor default
display block display block
margin 0 margin 0

View file

@ -14,13 +14,13 @@
<span class="username">@{ user.username }</span> <span class="username">@{ user.username }</span>
<span class="followed" if={ user.is_followed }>フォローされています</span> <span class="followed" if={ user.is_followed }>フォローされています</span>
</div> </div>
<div class="bio">{ user.bio }</div> <div class="description">{ user.description }</div>
<div class="info"> <div class="info">
<p class="location" if={ user.location }> <p class="location" if={ user.profile.location }>
<i class="fa fa-map-marker"></i>{ user.location } <i class="fa fa-map-marker"></i>{ user.profile.location }
</p> </p>
<p class="birthday" if={ user.birthday }> <p class="birthday" if={ user.profile.birthday }>
<i class="fa fa-birthday-cake"></i>{ user.birthday.replace('-', '年').replace('-', '月') + '日' } ({ age(user.birthday) }歳) <i class="fa fa-birthday-cake"></i>{ user.profile.birthday.replace('-', '年').replace('-', '月') + '日' } ({ age(user.profile.birthday) }歳)
</p> </p>
</div> </div>
<div class="friends"> <div class="friends">
@ -119,7 +119,7 @@
background #f8f8f8 background #f8f8f8
border-radius 4px border-radius 4px
> .bio > .description
margin 8px 0 margin 8px 0
color #333 color #333

View file

@ -134,7 +134,11 @@ describe('API', () => {
describe('i/update', () => { describe('i/update', () => {
it('アカウント設定を更新できる', () => new Promise(async (done) => { it('アカウント設定を更新できる', () => new Promise(async (done) => {
const me = await insertSakurako(); const me = await insertSakurako({
profile: {
gender: 'female'
}
});
const myName = '大室櫻子'; const myName = '大室櫻子';
const myLocation = '七森中'; const myLocation = '七森中';
@ -148,8 +152,10 @@ describe('API', () => {
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); res.body.should.be.a('object');
res.body.should.have.property('name').eql(myName); res.body.should.have.property('name').eql(myName);
res.body.should.have.property('location').eql(myLocation); res.body.should.have.property('profile').a('object');
res.body.should.have.property('birthday').eql(myBirthday); res.body.should.have.deep.property('profile.location').eql(myLocation);
res.body.should.have.deep.property('profile.birthday').eql(myBirthday);
res.body.should.have.deep.property('profile.gender').eql('female');
done(); done();
}); });
})); }));
@ -159,11 +165,12 @@ describe('API', () => {
birthday: '2000-09-07' birthday: '2000-09-07'
}); });
request('/i/update', { request('/i/update', {
birthday: '' birthday: null
}, me).then(res => { }, me).then(res => {
res.should.have.status(200); res.should.have.status(200);
res.body.should.be.a('object'); res.body.should.be.a('object');
res.body.should.have.property('birthday').eql(null); res.body.should.have.property('profile').a('object');
res.body.should.have.deep.property('profile.birthday').eql(null);
done(); done();
}); });
})); }));
@ -1214,7 +1221,8 @@ async function insertSakurako(opts) {
token: '!00000000000000000000000000000000', token: '!00000000000000000000000000000000',
username: 'sakurako', username: 'sakurako',
username_lower: 'sakurako', username_lower: 'sakurako',
password: '$2a$08$FnHXg3tP.M/kINWgQSXNqeoBsiVrkj.ecXX8mW9rfBzMRkibYfjYy' // HimawariDaisuki06160907 password: '$2a$08$FnHXg3tP.M/kINWgQSXNqeoBsiVrkj.ecXX8mW9rfBzMRkibYfjYy', // HimawariDaisuki06160907
profile: {}
}, opts)); }, opts));
} }
@ -1223,7 +1231,8 @@ async function insertHimawari(opts) {
token: '!00000000000000000000000000000001', token: '!00000000000000000000000000000001',
username: 'himawari', username: 'himawari',
username_lower: 'himawari', username_lower: 'himawari',
password: '$2a$08$OPESxR2RE/ZijjGanNKk6ezSqGFitqsbZqTjWUZPLhORMKxHCbc4O' // ilovesakurako password: '$2a$08$OPESxR2RE/ZijjGanNKk6ezSqGFitqsbZqTjWUZPLhORMKxHCbc4O', // ilovesakurako
profile: {}
}, opts)); }, opts));
} }

View file

@ -0,0 +1,18 @@
db.users.find({}).forEach(function(user) {
print(user._id);
db.users.update({ _id: user._id }, {
$rename: {
bio: 'description'
},
$unset: {
location: '',
birthday: ''
},
$set: {
profile: {
location: user.location || null,
birthday: user.birthday || null
}
}
}, false, false);
});