doortts doortts 2016-11-10
user: Support user token
@cabadab1b8240ee727956dd39481dc201e40edee
app/controllers/UserApp.java
--- app/controllers/UserApp.java
+++ app/controllers/UserApp.java
@@ -21,11 +21,11 @@
 
 import com.avaje.ebean.ExpressionList;
 import com.avaje.ebean.annotation.Transactional;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import controllers.annotation.AnonymousCheck;
 import models.*;
 import models.enumeration.Operation;
 import models.enumeration.UserState;
-
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.crypto.RandomNumberGenerator;
@@ -43,6 +43,7 @@
 import play.mvc.Http.Cookie;
 import utils.*;
 import views.html.user.*;
+import org.joda.time.LocalDateTime;
 
 import java.util.*;
 
@@ -579,6 +580,14 @@
                 return ok(edit_notifications.render(userForm, user));
             case EMAILS:
                 return ok(edit_emails.render(userForm, user));
+            case TOKEN_RESET:
+                user.token = null;
+            case TOKEN:
+                if( StringUtils.isEmpty(user.token)){
+                    user.token = new Sha256Hash(LocalDateTime.now().toString()).toBase64();
+                    user.save();
+                }
+                return ok(edit_token.render(userForm, user));
             default:
             case PROFILE:
                 return ok(edit.render(userForm, user));
@@ -589,7 +598,9 @@
         PROFILE("profile"),
         PASSWORD("password"),
         NOTIFICATIONS("notifications"),
-        EMAILS("emails");
+        EMAILS("emails"),
+        TOKEN("token"),
+        TOKEN_RESET("token_reset");
 
         private String tabId;
 
app/models/User.java
--- app/models/User.java
+++ app/models/User.java
@@ -97,6 +97,7 @@
     public String passwordSalt;
     @Constraints.Email(message = "user.wrongEmail.alert")
     public String email;
+    public String token;
 
     @Transient
     private Boolean siteManager;
 
app/views/user/edit_token.scala.html (added)
+++ app/views/user/edit_token.scala.html
@@ -0,0 +1,53 @@
+@**
+* Yobi, Project Hosting SW
+*
+* Copyright 2012 NAVER Corp.
+* http://yobi.io
+*
+* @author Ahn Hyeok Jun
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+**@
+@(userForm: play.data.Form[User], user:User)
+
+@import helper._
+@import utils.TemplateHelper._
+
+@siteLayout(user.loginId, utils.MenuType.USER) {
+<div class="site-breadcrumb-outer">
+    <div class="site-breadcrumb-inner">
+        <h3>@Messages("userinfo.token")</h3>
+    </div>
+</div>
+<div class="page-wrap-outer">
+    <div class="page-wrap">
+        @partial_edit_tabmenu("token")
+        <div class="token-generate">
+            <form id="frmBasic" method="post" action="@routes.UserApp.editUserInfoByTabForm("token_reset")" class="pull-left" style="width:100%">
+                <div>@Messages("userinfo.token")</div>
+                <div>
+                    <input onClick="this.setSelectionRange(0, this.value.length)" size="45" style="width: 90%" type="text" name="name" class="text" value="@user.token" readonly>
+                </div>
+                <div>
+                    <button type="submit" class="ybtn ybtn-success">@Messages("userinfo.recreateToken")</button>
+                </div>
+            </form>
+        </div>
+    </div>
+</div>
+<script type="text/javascript">
+    $(function(){
+        $yobi.loadModule("user.Setting");
+    });
+</script>
+}
app/views/user/partial_edit_tabmenu.scala.html
--- app/views/user/partial_edit_tabmenu.scala.html
+++ app/views/user/partial_edit_tabmenu.scala.html
@@ -40,4 +40,9 @@
     @Messages("userinfo.changeEmails")
     </a>
   </li>
+  <li @if(tabId == "token"){ class="active" }>
+    <a href="@routes.UserApp.editUserInfoByTabForm("token")">
+    @Messages("userinfo.token")
+    </a>
+  </li>
 </ul>
 
conf/evolutions/default/6.sql (added)
+++ conf/evolutions/default/6.sql
@@ -0,0 +1,7 @@
+# --- !Ups
+ALTER TABLE n4user ADD COLUMN token varchar(255);
+CREATE UNIQUE INDEX uq_n4user_token ON n4user (token);
+
+# --- !Downs
+DROP INDEX IF EXISTS uq_n4user_token;
+ALTER TABLE n4user DROP COLUMN token;
conf/messages
--- conf/messages
+++ conf/messages
@@ -965,6 +965,8 @@
 userinfo.leaveProject.confirm = Are you sure to leave {0}?
 userinfo.profile = My profile
 userinfo.since = Member since
+userinfo.token = User Token
+userinfo.recreateToken = Recreate User Token
 validation.allowedCharsForLoginId = Login id may contain alphanumeric characters including dash, underscore or dot, but cannot begin or end with underscore or dot.
 validation.duplicated = Already exists!
 validation.invalidEmail = Enter valid email address!
conf/messages.ko-KR
--- conf/messages.ko-KR
+++ conf/messages.ko-KR
@@ -958,6 +958,8 @@
 userinfo.leaveProject.confirm = 정말 {0} 프로젝트에서 탈퇴하시겠습니까?
 userinfo.profile = 마이 페이지
 userinfo.since = 가입일
+userinfo.token = 사용자토큰
+userinfo.recreateToken = 사용자토큰 다시생성
 validation.allowedCharsForLoginId = 아이디는 알파벳 숫자 - _ . 를 포함할 수 있으나 _ . 로 시작하거나 끝날 수 없습니다.
 validation.duplicated = 이미 존재합니다!
 validation.invalidEmail = 올바른 이메일을 입력해 주세요.
conf/routes
--- conf/routes
+++ conf/routes
@@ -63,6 +63,7 @@
 POST           /users/signup                                                          controllers.UserApp.newUser()
 GET            /user/editform                                                         controllers.UserApp.editUserInfoForm()
 GET            /user/editform/:tabId                                                  controllers.UserApp.editUserInfoByTabForm(tabId: String)
+POST            /user/editform/:tabId                                                  controllers.UserApp.editUserInfoByTabForm(tabId: String)
 POST           /user/edit                                                             controllers.UserApp.editUserInfo()
 POST           /user/resetPassword                                                    controllers.UserApp.resetUserPassword()
 GET            /user/isUsed                                                           controllers.UserApp.isUsed(name:String)
Add a comment
List