|
@@ -7,11 +7,13 @@ import {
|
|
|
import { Observable } from 'rxjs';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { textbookServer } from '../../services/textbook';
|
|
|
+import Parse from 'parse';
|
|
|
+
|
|
|
@Injectable({
|
|
|
providedIn: 'root',
|
|
|
})
|
|
|
export class AuthGuard implements CanActivate {
|
|
|
- LoginPage = '/user/login';
|
|
|
+ LoginPage = 'external/404';
|
|
|
constructor(private tbookSer: textbookServer, private router: Router) {}
|
|
|
canActivate(
|
|
|
next: ActivatedRouteSnapshot,
|
|
@@ -36,24 +38,57 @@ export class AuthGuard implements CanActivate {
|
|
|
.then((data) => {
|
|
|
console.log(data.data);
|
|
|
if (data.data.rs == 0) {
|
|
|
- // window.location.href =
|
|
|
- // 'https://audit.hep.com.cn/admin/401?noGoBack=0';
|
|
|
+ window.location.href =
|
|
|
+ 'https://audit.hep.com.cn/admin/401?noGoBack=0';
|
|
|
this.router.navigate([this.LoginPage]);
|
|
|
resolve(false);
|
|
|
+ // Parse.User.logIn('145review', 'review-textbook145').then((user) => {
|
|
|
+ // resolve(true);
|
|
|
+ // })
|
|
|
+ // Parse.User.become('r:4d692312d4b08d4120981152e67428f8')
|
|
|
+ // .then((user) => resolve(true))
|
|
|
+ // .catch((err) => {
|
|
|
+ // resolve(false);
|
|
|
+ // this.router.navigate([this.LoginPage]);
|
|
|
+ // });
|
|
|
} else {
|
|
|
-
|
|
|
- resolve(true);
|
|
|
+ if (!Parse.User.current()?.id) {
|
|
|
+ fetch('https://145.tbook.com.cn/api/textbook/review/token', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .then((response) => response.json())
|
|
|
+ .then(async (res) => {
|
|
|
+ Parse.User.become(
|
|
|
+ res?.token || 'r:4d692312d4b08d4120981152e67428f8'
|
|
|
+ )
|
|
|
+ .then((user) => resolve(true))
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err);
|
|
|
+ window.location.href =
|
|
|
+ 'https://audit.hep.com.cn/admin/401?noGoBack=0';
|
|
|
+ resolve(false);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error('获取token失败:', error);
|
|
|
+ resolve(false);
|
|
|
+ this.router.navigate([this.LoginPage]);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ resolve(true);
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
console.error('Error:', error); // 处理错误
|
|
|
+ window.location.href =
|
|
|
+ 'https://audit.hep.com.cn/admin/401?noGoBack=0';
|
|
|
+ resolve(false);
|
|
|
});
|
|
|
});
|
|
|
- // if (this.tbookSer.profile.identity == '国家级管理员') {
|
|
|
- // return true;
|
|
|
- // }
|
|
|
- // this.router.navigate([this.LoginPage]);
|
|
|
- // return false;
|
|
|
}
|
|
|
}
|
|
|
export { CanActivate };
|