forked from jobmission/oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhang wanchao
committed
Mar 28, 2018
1 parent
8ce85a8
commit 4a031cf
Showing
16 changed files
with
390 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/main/java/com/revengemission/sso/oauth2/server/controller/IndexController.java
This file was deleted.
Oops, something went wrong.
66 changes: 63 additions & 3 deletions
66
src/main/java/com/revengemission/sso/oauth2/server/controller/ProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/revengemission/sso/oauth2/server/domain/EntityNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
25 changes: 25 additions & 0 deletions
25
src/main/java/com/revengemission/sso/oauth2/server/domain/GenderEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/revengemission/sso/oauth2/server/domain/ParameterException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.