diff --git a/core/amber/src/main/scala/edu/uci/ics/texera/web/TexeraWebApplication.scala b/core/amber/src/main/scala/edu/uci/ics/texera/web/TexeraWebApplication.scala index 020a3135ea9..7581b7d4094 100644 --- a/core/amber/src/main/scala/edu/uci/ics/texera/web/TexeraWebApplication.scala +++ b/core/amber/src/main/scala/edu/uci/ics/texera/web/TexeraWebApplication.scala @@ -23,7 +23,6 @@ import edu.uci.ics.texera.web.resource.dashboard.user.dataset.{ DatasetAccessResource, DatasetResource } -import edu.uci.ics.texera.web.resource.dashboard.user.discussion.UserDiscussionResource import edu.uci.ics.texera.web.resource.dashboard.user.project.{ ProjectAccessResource, ProjectResource, @@ -147,7 +146,6 @@ class TexeraWebApplication environment.jersey.register(classOf[GmailResource]) environment.jersey.register(classOf[AdminExecutionResource]) environment.jersey.register(classOf[UserQuotaResource]) - environment.jersey.register(classOf[UserDiscussionResource]) environment.jersey.register(classOf[AIAssistantResource]) } } diff --git a/core/amber/src/main/scala/edu/uci/ics/texera/web/resource/dashboard/user/discussion/UserDiscussionResource.scala b/core/amber/src/main/scala/edu/uci/ics/texera/web/resource/dashboard/user/discussion/UserDiscussionResource.scala deleted file mode 100644 index 366ec835b8f..00000000000 --- a/core/amber/src/main/scala/edu/uci/ics/texera/web/resource/dashboard/user/discussion/UserDiscussionResource.scala +++ /dev/null @@ -1,41 +0,0 @@ -package edu.uci.ics.texera.web.resource.dashboard.user.discussion - -import com.mysql.cj.jdbc.MysqlDataSource -import edu.uci.ics.amber.core.storage.StorageConfig -import edu.uci.ics.texera.web.auth.SessionUser -import io.dropwizard.auth.Auth -import org.jooq.SQLDialect -import org.jooq.impl.DSL.{field, name, table, using} -import org.mindrot.jbcrypt.BCrypt.{gensalt, hashpw} - -import javax.ws.rs._ -import javax.ws.rs.core.MediaType - -@Path("/discussion") -class UserDiscussionResource { - - @PUT - @Path("/register") - @Produces(Array(MediaType.APPLICATION_JSON)) - def register(@Auth user: SessionUser): Int = { - val dataSource = new MysqlDataSource - dataSource.setUrl(StorageConfig.jdbcUrl.replace("texera_db", "flarum")) - dataSource.setUser(StorageConfig.jdbcUsername) - dataSource.setPassword(StorageConfig.jdbcPassword) - using(dataSource, SQLDialect.MYSQL) - .insertInto(table(name("users"))) - .columns( - field(name("username")), - field(name("email")), - field(name("is_email_confirmed")), - field(name("password")) - ) - .values( - user.getEmail, - user.getEmail, - "1", - hashpw(user.getGoogleId, gensalt()) - ) - .execute() - } -} diff --git a/core/gui/src/app/app.module.ts b/core/gui/src/app/app.module.ts index 66c5c13ca9d..c477a8af9c0 100644 --- a/core/gui/src/app/app.module.ts +++ b/core/gui/src/app/app.module.ts @@ -240,6 +240,7 @@ registerLocaleData(en); tokenGetter: AuthService.getAccessToken, skipWhenExpired: false, throwNoTokenError: false, + disallowedRoutes: ["forum/api/users"], }, }), BrowserAnimationsModule, diff --git a/core/gui/src/app/dashboard/component/dashboard.component.ts b/core/gui/src/app/dashboard/component/dashboard.component.ts index 4ccd65d41ad..f825801c71e 100644 --- a/core/gui/src/app/dashboard/component/dashboard.component.ts +++ b/core/gui/src/app/dashboard/component/dashboard.component.ts @@ -56,26 +56,6 @@ export class DashboardComponent implements OnInit { this.isCollpased = false; - if (!document.cookie.includes("flarum_remember") && this.isLogin) { - this.flarumService - .auth() - .pipe(untilDestroyed(this)) - .subscribe({ - next: (response: any) => { - document.cookie = `flarum_remember=${response.token};path=/`; - }, - error: (err: unknown) => { - if ([404, 500].includes((err as HttpErrorResponse).status)) { - this.displayForum = false; - } else { - this.flarumService - .register() - .pipe(untilDestroyed(this)) - .subscribe(() => this.ngOnInit()); - } - }, - }); - } this.router.events.pipe(untilDestroyed(this)).subscribe(() => { this.checkRoute(); }); @@ -94,11 +74,35 @@ export class DashboardComponent implements OnInit { this.ngZone.run(() => { this.isLogin = this.userService.isLogin(); this.isAdmin = this.userService.isAdmin(); + this.forumLogin(); this.cdr.detectChanges(); }); }); } + forumLogin() { + if (!document.cookie.includes("flarum_remember") && this.isLogin) { + this.flarumService + .auth() + .pipe(untilDestroyed(this)) + .subscribe({ + next: (response: any) => { + document.cookie = `flarum_remember=${response.token};path=/`; + }, + error: (err: unknown) => { + if ([404, 500].includes((err as HttpErrorResponse).status)) { + this.displayForum = false; + } else { + this.flarumService + .register() + .pipe(untilDestroyed(this)) + .subscribe(() => this.forumLogin()); + } + }, + }); + } + } + checkRoute() { const currentRoute = this.router.url; this.displayNavbar = this.isNavbarEnabled(currentRoute); diff --git a/core/gui/src/app/dashboard/service/user/flarum/flarum.service.ts b/core/gui/src/app/dashboard/service/user/flarum/flarum.service.ts index 9853912893c..ec6e077f69e 100644 --- a/core/gui/src/app/dashboard/service/user/flarum/flarum.service.ts +++ b/core/gui/src/app/dashboard/service/user/flarum/flarum.service.ts @@ -1,7 +1,6 @@ import { Injectable } from "@angular/core"; import { HttpClient } from "@angular/common/http"; import { UserService } from "../../../../common/service/user/user.service"; -import { AppSettings } from "../../../../common/app-setting"; @Injectable({ providedIn: "root", @@ -11,16 +10,22 @@ export class FlarumService { private http: HttpClient, private userService: UserService ) {} - public register() { - return this.http.put(`${AppSettings.getApiEndpoint()}/discussion/register`, {}); - } - auth() { - const currentUser = this.userService.getCurrentUser(); + register() { + const user = this.userService.getCurrentUser(); return this.http.post( - "forum/api/token", - { identification: currentUser!.email, password: currentUser!.googleId, remember: "1" }, - { headers: { "Content-Type": "application/json" }, withCredentials: true } + "forum/api/users", + { + data: { + attributes: { username: user!.email.split("@")[0] + user!.uid, email: user!.email, password: user!.googleId }, + }, + }, + { headers: { Authorization: "Token hdebsyxiigyklxgsqivyswwiisohzlnezzzzzzzz;userId=1" } } ); } + + auth() { + const user = this.userService.getCurrentUser(); + return this.http.post("forum/api/token", { identification: user!.email, password: user!.googleId, remember: "1" }); + } }