From 06811057789bca389d82c11ab639d68892dbbaab Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Sat, 13 Jun 2020 18:42:59 +0530 Subject: [PATCH] Uses only token now Need to implement timeout later --- .../doge/chatto/ApplicationController.scala | 3 +-- .../chatto/controller/LoginController.scala | 2 +- .../wow/doge/chatto/service/UserService.scala | 20 ++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/scala/wow/doge/chatto/ApplicationController.scala b/src/main/scala/wow/doge/chatto/ApplicationController.scala index 45a994d..9a715d2 100644 --- a/src/main/scala/wow/doge/chatto/ApplicationController.scala +++ b/src/main/scala/wow/doge/chatto/ApplicationController.scala @@ -103,11 +103,10 @@ class ApplicationController extends DefaultWindowController { final case class ApplicationName(name: String) final case class UserCredentials( username: String, - password: String, token: String ) object UserCredentials { - def empty = UserCredentials("empty", "empty", "empty") + def empty = UserCredentials("empty", "empty") } @ApplicationScoped diff --git a/src/main/scala/wow/doge/chatto/controller/LoginController.scala b/src/main/scala/wow/doge/chatto/controller/LoginController.scala index e82eac4..a74cd88 100644 --- a/src/main/scala/wow/doge/chatto/controller/LoginController.scala +++ b/src/main/scala/wow/doge/chatto/controller/LoginController.scala @@ -78,7 +78,7 @@ class LoginController @Inject() ( case Some(token) => async { val credentials = - UserCredentials(inputUserName, inputPassword, token) + UserCredentials(inputUserName, token) appDataHandler.updateCredentials(credentials) updateErrorLabel("") applicationController.showChatPane() diff --git a/src/main/scala/wow/doge/chatto/service/UserService.scala b/src/main/scala/wow/doge/chatto/service/UserService.scala index c226131..d1a76d2 100644 --- a/src/main/scala/wow/doge/chatto/service/UserService.scala +++ b/src/main/scala/wow/doge/chatto/service/UserService.scala @@ -32,10 +32,13 @@ class UserService @Inject() (appDataHandler: AppDataHandler)( DefaultFormats ++ JavaTimeSerializers.all private val domain = "http://localhost:8080" private lazy val baseUrl = uri"$domain/api/chat" - private lazy val authBasicRequest = (credentials: UserCredentials) => - basicRequest.auth - .basic(credentials.username, credentials.password) - .header("X-AUTH-TOKEN", credentials.token) + // private lazy val authBasicRequest = (credentials: UserCredentials) => + // basicRequest.auth + // .basic(credentials.username, credentials.password) + // .header("X-AUTH-TOKEN", credentials.token) + private lazy val tokenBasicRequest = (token: String) => { + basicRequest.header("X-AUTH-TOKEN", token) + } def func1() = async { val willBeResponse = func2() @@ -59,7 +62,8 @@ class UserService @Inject() (appDataHandler: AppDataHandler)( // ) // ) await { - authBasicRequest(credentials) + // authBasicRequest(credentials) + tokenBasicRequest(credentials.token) .get(uri"http://localhost:8080/api/chat/get/users") .response(asJson[List[String]]) .send() @@ -69,7 +73,8 @@ class UserService @Inject() (appDataHandler: AppDataHandler)( def getMessages(credentials: UserCredentials) = async { // logger.debug(s"${appDataHandler.appData}") await { - authBasicRequest(credentials) + // authBasicRequest(credentials) + tokenBasicRequest(credentials.token) .get(uri"http://localhost:8080/api/chat/get/users") .response(asJson[List[String]]) .send() @@ -77,7 +82,8 @@ class UserService @Inject() (appDataHandler: AppDataHandler)( } def getActiveUsers(credentials: UserCredentials) = - authBasicRequest(credentials) + // authBasicRequest(credentials) + tokenBasicRequest(credentials.token) .get(uri"http://localhost:8080/api/chat/get/active-users") .response(asJson[List[ActiveUser]]) .send()