Skip to content

Commit

Permalink
update profile
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang wanchao committed Mar 28, 2018
1 parent 8ce85a8 commit 4a031cf
Show file tree
Hide file tree
Showing 16 changed files with 390 additions and 39 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

QA
<groupId>com.revengemission.sso</groupId>
<artifactId>oauth2-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>oauth2-server</name>
<description>oauth2-server with resource server</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Component
public class WebRequestLogAspect {

private static Logger logger = LoggerFactory.getLogger(WebRequestLogAspect.class);
private Logger log = LoggerFactory.getLogger(this.getClass());

@Pointcut("execution(public * com.revengemission.sso.oauth2.server.controller.*.*(..))")
public void wsLog() {
Expand Down Expand Up @@ -54,15 +54,15 @@ public void doBefore(JoinPoint joinPoint) throws Throwable {
if (object != null) {
requestBody = JSONUtil.objectToJSONString(object);
}
logger.info("\nRequest from " + request.getRemoteHost() +
log.info("\nRequest from " + request.getRemoteHost() +
";\nHeaders =" + JSONUtil.objectToJSONString(getHeadersInfo(request)) +
";\nuri =" + request.getRequestURL().toString() +
"; \nrequest method=" + request.getMethod() +
"; \ncontent type=" + request.getContentType() +
";\nrequest parameters=" + parametersString +
";\nrequest body=" + requestBody);
} catch (Exception e) {
logger.info("Request Object To Json Exception: " + e);
log.info("Request Object To Json Exception: " + e);
}
}

Expand All @@ -72,9 +72,9 @@ public void doBefore(JoinPoint joinPoint) throws Throwable {
public void doAfterReturning(Object ret) throws Throwable {
// 处理完请求,返回内容
try {
logger.info("Response from server : \n" + JSONUtil.objectToJSONString(ret));
log.info("Response from server : \n" + JSONUtil.objectToJSONString(ret));
} catch (Exception e) {
logger.info("Response Object To Json Exception:\n " + e);
log.info("Response Object To Json Exception:\n " + e);
}

}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,95 @@
package com.revengemission.sso.oauth2.server.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.revengemission.sso.oauth2.server.domain.EntityNotFoundException;
import com.revengemission.sso.oauth2.server.domain.UserAccount;
import com.revengemission.sso.oauth2.server.service.UserAccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class ProfileController {

private Logger log = LoggerFactory.getLogger(this.getClass());

@Autowired
UserAccountService userAccountService;

@ResponseBody
@GetMapping("/user/me")
public Map<String, String> info(Principal principal) {
Map<String, String> result = new HashMap<>();
result.put("username", principal.getName());
try {
UserAccount userAccount = userAccountService.findByUsername(principal.getName());
result.put("username", principal.getName());
result.put("gender", userAccount.getGender());
} catch (EntityNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("findByUsername exception", e);
}
}

return result;
}

@GetMapping("/user/profile")
@GetMapping(value = {"/", "/user/profile"})
public String profile(Principal principal,
Model model) {
try {
UserAccount userAccount = userAccountService.findByUsername(principal.getName());
model.addAttribute("userAccount", userAccount);
} catch (EntityNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("findByUsername exception", e);
}
}

return "profile";
}

@PostMapping("/user/profile")
public String handleProfile(Principal principal,
@RequestParam(value = "nickName", required = false) String nickName,
@RequestParam(value = "avatarUrl", required = false) String avatarUrl,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "mobile", required = false) String mobile,
@RequestParam(value = "province", required = false) String province,
@RequestParam(value = "city", required = false) String city,
@RequestParam(value = "address", required = false) String address,
@JsonFormat(pattern = "MM-dd-yyyy") @DateTimeFormat(pattern = "MM-dd-yyyy")
@RequestParam(value = "birthday", required = false) Date birthday,
Model model) {
return "profile";

try {
UserAccount userAccount = userAccountService.findByUsername(principal.getName());
userAccount.setNickName(nickName);
userAccount.setAvatarUrl(avatarUrl);
userAccount.setEmail(email);
userAccount.setMobile(mobile);
userAccount.setProvince(province);
userAccount.setCity(city);
userAccount.setAddress(address);
userAccount.setBirthday(birthday);
userAccountService.updateById(userAccount);
} catch (EntityNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("findByUsername exception", e);
}
}

return "redirect:/user/profile";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String handleSignUp(HttpServletRequest request,
userAccount.setRole(RoleEnum.ROLE_USER.name());
userAccount.setUsername(username);
userAccount.setPassword(passwordEncoder.encode(password));
userAccountService.create(userAccount);
userAccount = userAccountService.create(userAccount);
return "redirect:/?success=signUp";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.revengemission.sso.oauth2.server.domain;

import java.io.IOException;

public class EntityNotFoundException extends IOException {
public EntityNotFoundException() {
}

public EntityNotFoundException(String message) {
super(message);
}
}


















































Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.revengemission.sso.oauth2.server.domain;

public enum GenderEnum {

MALE("男"),
FEMALE("女"),
UNKNOWN("未知");

private String meaning;

public String getMeaning() {
return meaning;
}

public void setMeaning(String meaning) {
this.meaning = meaning;
}

GenderEnum() {
}

GenderEnum(String meaning) {
this.meaning = meaning;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.revengemission.sso.oauth2.server.domain;

public class ParameterException extends RuntimeException {
public ParameterException() {
}

public ParameterException(String message) {
super(message);
}
}


















































Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.Date;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserAccount extends BaseDomain {
private String username;
Expand All @@ -14,6 +16,8 @@ public class UserAccount extends BaseDomain {
private String province;
private String city;
private String address;
private Date birthday;
private String gender;

public String getUsername() {
return username;
Expand Down Expand Up @@ -94,4 +98,20 @@ public String getAddress() {
public void setAddress(String address) {
this.address = address;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}
}
Loading

0 comments on commit 4a031cf

Please sign in to comment.