
refactoring user profile avatar
@1f25fe0df5b39454f5645507a9d864e467dbf1bb
--- app/controllers/UserApp.java
+++ app/controllers/UserApp.java
... | ... | @@ -160,6 +160,7 @@ |
160 | 160 |
return badRequest(signup.render("title.signup", newUserForm)); |
161 | 161 |
else { |
162 | 162 |
User user = newUserForm.get(); |
163 |
+ user.avatarUrl = "/assets/images/default-avatar-128.png"; |
|
163 | 164 |
User.create(hashedPassword(user)); |
164 | 165 |
|
165 | 166 |
setUserInfoInSession(user); |
... | ... | @@ -236,10 +237,14 @@ |
236 | 237 |
User user = UserApp.currentUser(); |
237 | 238 |
user.email = userForm.data().get("email"); |
238 | 239 |
user.name = userForm.data().get("name"); |
239 |
- user.update(); |
|
240 |
- |
|
240 |
+ |
|
241 | 241 |
Attachment.deleteAll(Resource.USER_AVATAR, currentUser().id); |
242 |
- Attachment.attachFiles(currentUser().id, null, Resource.USER_AVATAR, currentUser().id); |
|
242 |
+ int attachFiles = Attachment.attachFiles(currentUser().id, null, Resource.USER_AVATAR, currentUser().id); |
|
243 |
+ if(attachFiles>0) { |
|
244 |
+ user.avatarUrl = "/files/" + user.avatarId(); |
|
245 |
+ } |
|
246 |
+ |
|
247 |
+ user.update(); |
|
243 | 248 |
return redirect(routes.UserApp.userInfo(user.loginId)); |
244 | 249 |
} |
245 | 250 |
|
--- app/models/Attachment.java
+++ app/models/Attachment.java
... | ... | @@ -91,7 +91,7 @@ |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
// Attach the files from the user's temporary area to the given container. |
94 |
- public static void attachFiles( |
|
94 |
+ public static int attachFiles( |
|
95 | 95 |
Long userId, Long projectId, Resource containerType, Long containerId) { |
96 | 96 |
// Move the attached files in the temporary area to the issue area. |
97 | 97 |
List<Attachment> attachments = Attachment.findTempFiles(userId); |
... | ... | @@ -101,6 +101,7 @@ |
101 | 101 |
attachment.containerId = containerId; |
102 | 102 |
attachment.save(); |
103 | 103 |
} |
104 |
+ return attachments.size(); |
|
104 | 105 |
} |
105 | 106 |
|
106 | 107 |
// Store the files in the filesystem. |
--- app/models/User.java
+++ app/models/User.java
... | ... | @@ -131,16 +131,7 @@ |
131 | 131 |
.ne("projectUser.role.id", RoleType.SITEMANAGER.roleType()) |
132 | 132 |
.findList(); |
133 | 133 |
} |
134 |
- |
|
135 |
- public static Long avatartIdByLoginId(String loginId) { |
|
136 |
- return findByLoginId(loginId).avatarId(); |
|
137 |
- } |
|
138 |
- |
|
139 |
- @Cached(key = "isCustomAvatar") |
|
140 |
- public boolean isCustomAvatar() { |
|
141 |
- return Attachment.findByContainer(Resource.USER_AVATAR, id).size()>0 ? true : false; |
|
142 |
- } |
|
143 |
- |
|
134 |
+ |
|
144 | 135 |
public Long avatarId(){ |
145 | 136 |
return Attachment.findByContainer(Resource.USER_AVATAR, id).get(0).id; |
146 | 137 |
} |
--- app/views/board/postList.scala.html
+++ app/views/board/postList.scala.html
... | ... | @@ -66,7 +66,7 @@ |
66 | 66 |
<i class="ico ico-comment-bubble"></i><span class="num">@post.commentCount</span> |
67 | 67 |
</div> |
68 | 68 |
<a href="@routes.UserApp.userInfo(post.authorLoginId)" class="author-avatar img-rounded pull-right"> |
69 |
- <img class="user-picture" src="@urlToPicture(User.find.byId(post.authorId).email, 34)" alt="@post.authorName"> |
|
69 |
+ <img class="user-picture" src="@User.findByLoginId(session.get("loginId")).avatarUrl" width="34" height="34" alt="@post.authorName"> |
|
70 | 70 |
</div> |
71 | 71 |
</li> |
72 | 72 |
} |
--- app/views/user/edit.scala.html
+++ app/views/user/edit.scala.html
... | ... | @@ -14,11 +14,7 @@ |
14 | 14 |
<div class="bubble-wrap dark-gray project-home"> |
15 | 15 |
<div class="inner logo"> |
16 | 16 |
<div class="logo-wrap"> |
17 |
- @if(user.isCustomAvatar()) { |
|
18 |
- <img src="@routes.AttachmentApp.getFile(user.avatarId())" width="34"/> |
|
19 |
- } else { |
|
20 |
- <img src="@routes.Assets.at("images/default-avatar-128.png")" /> |
|
21 |
- } |
|
17 |
+ <img src="@user.avatarUrl" /> |
|
22 | 18 |
</div> |
23 | 19 |
<div id="picPath">업로드된 파일이 없습니다.</div> |
24 | 20 |
<input id="attachmemt" type="file" name="filePath"/> |
--- app/views/user/info.scala.html
+++ app/views/user/info.scala.html
... | ... | @@ -13,11 +13,7 @@ |
13 | 13 |
<div class="bubble-wrap dark-gray project-home"> |
14 | 14 |
<div class="inner logo"> |
15 | 15 |
<div class="logo-wrap"> |
16 |
- @if(user.isCustomAvatar()) { |
|
17 |
- <img src="@routes.AttachmentApp.getFile(user.avatarId())" /> |
|
18 |
- } else { |
|
19 |
- <img src="@routes.Assets.at("images/default-avatar-128.png")" /> |
|
20 |
- } |
|
16 |
+ <img src="@user.avatarUrl" /> |
|
21 | 17 |
</div> |
22 | 18 |
</div> |
23 | 19 |
<div class="inner project-info"> |
--- conf/initial-data.yml
+++ conf/initial-data.yml
... | ... | @@ -6,35 +6,41 @@ |
6 | 6 |
password: 5v4TVjzLo1bqullT1CU4/bENUNOUfX97WpdunGLvJvw= |
7 | 7 |
passwordSalt: '[B@1032a4' |
8 | 8 |
email: admin@nhn.com |
9 |
+ avatarUrl: /assets/images/default-avatar-128.png |
|
9 | 10 |
- !!models.User |
10 | 11 |
name: Hobi |
11 | 12 |
loginId: hobi |
12 | 13 |
password: ys9gr1Xet/DL9RpmgczOlJg+txPvqnZCaw/z55gb0KU= |
13 | 14 |
passwordSalt: '[B@1032a4' |
14 | 15 |
email: hobi@nhn.com |
16 |
+ avatarUrl: /assets/images/default-avatar-128.png |
|
15 | 17 |
- !!models.User |
16 | 18 |
name: scott |
17 | 19 |
loginId: k16wire |
18 | 20 |
password: v1O5ggs2TqM0prM1pLUD/zC+g7cavbWMXayVA9pvGHY= |
19 | 21 |
passwordSalt: '[B@1032a4' |
20 | 22 |
email: k16wire@naver.com |
23 |
+ avatarUrl: /assets/images/default-avatar-128.png |
|
21 | 24 |
- !!models.User |
22 | 25 |
name: suwon |
23 | 26 |
loginId: doortts |
24 | 27 |
password: rB5DBMe0hxMWs5FlQOJi5GmK+wj2Txx09MdgFqH83+k= |
25 | 28 |
passwordSalt: '[B@1032a4' |
26 | 29 |
email: doortts@gmail.com |
30 |
+ avatarUrl: /assets/images/default-avatar-128.png |
|
27 | 31 |
- !!models.User |
28 | 32 |
name: eungjun |
29 | 33 |
loginId: nori |
30 | 34 |
password: yOF0X0iKA1MVkaAJESNcdGE1n/3SWM8vDOKRYCXV2E0= |
31 | 35 |
passwordSalt: '[B@1032a4' |
32 | 36 |
email: ejlee@nhn.com |
37 |
+ avatarUrl: /assets/images/default-avatar-128.png |
|
33 | 38 |
- !!models.User |
34 | 39 |
name: anonymous |
35 | 40 |
loginId: anonymous |
36 | 41 |
password: |
37 | 42 |
email: anonymous@nhn.com |
43 |
+ avatarUrl: /assets/images/default-avatar-128.png |
|
38 | 44 |
|
39 | 45 |
# Projects |
40 | 46 |
projects: |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?