3333import io .jsonwebtoken .Claims ;
3434import io .swagger .annotations .Api ;
3535import io .swagger .annotations .ApiOperation ;
36+ import org .casbin .casdoor .entity .CasdoorUser ;
37+ import org .casbin .casdoor .service .CasdoorAuthService ;
3638import org .slf4j .Logger ;
3739import org .slf4j .LoggerFactory ;
3840import org .springframework .beans .factory .annotation .Autowired ;
@@ -53,6 +55,8 @@ public class UserController {
5355
5456 private static final Logger logger = LoggerFactory .getLogger (UserController .class );
5557
58+ @ Autowired private CasdoorAuthService casdoorAuthService ;
59+
5660 @ PostMapping ("/login" )
5761 @ ApiOperation ("login" )
5862 public BaseVO <ConnectionVO > login (
@@ -71,6 +75,35 @@ public BaseVO<ConnectionVO> login(
7175 return BaseVO .success ("Login successful" , connectionVO );
7276 }
7377
78+ @ PostMapping ("/getCasdoorUrl" )
79+ @ ApiOperation ("Get Casdoor Url" )
80+ public BaseVO <String > getCasdoorUrl (HttpServletRequest request , HttpServletResponse response )
81+ throws BaseException {
82+ String origin = request .getParameter ("origin" );
83+ String url = casdoorAuthService .getSigninUrl (origin );
84+ return BaseVO .success ("Get Url successful" , url );
85+ }
86+
87+ @ PostMapping ("/loginWithCasdoor" )
88+ @ ApiOperation ("loginWithCasdoor" )
89+ public BaseVO <ConnectionVO > loginWithCasdoor (
90+ @ RequestParam ("code" ) String code ,
91+ @ RequestParam ("state" ) String state ,
92+ HttpServletResponse response )
93+ throws BaseException {
94+ String token = casdoorAuthService .getOAuthToken (code , state );
95+ CasdoorUser casdoorUser = casdoorAuthService .parseJwtToken (token );
96+ User user = new User ();
97+ user .setId (casdoorUser .getRanking ());
98+ user .setName (casdoorUser .getName ());
99+ int userId = user .getId ();
100+ String name = user .getName ();
101+ List <ConnVO > connVOs = connectionService .getAllConnections (userId );
102+ ConnectionVO connectionVO = new ConnectionVO (connVOs , userId , name );
103+ response .addHeader ("Authorization" , JJwtTool .generateToken (user ));
104+ return BaseVO .success ("Login successful" , connectionVO );
105+ }
106+
74107 @ PostMapping ("/save" )
75108 @ ApiOperation ("Create user (not used)" )
76109 public BaseVO save (@ RequestBody User user ) throws BaseException {
0 commit comments