-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
🔀 Merge pull request #12 from yoavst/feature/multiuser
Feature/multiuser
- Loading branch information
Showing
35 changed files
with
1,182 additions
and
253 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
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
64 changes: 64 additions & 0 deletions
64
backends/clion/src/main/kotlin/com/yoavst/graffiti/intellij/authentication.kt
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,64 @@ | ||
package com.yoavst.graffiti.intellij | ||
|
||
import com.intellij.openapi.diagnostic.Logger | ||
import java.io.File | ||
import java.util.* | ||
|
||
private val logger = Logger.getInstance(EnableGraffitiSyncAction::class.java) | ||
|
||
private fun getTokenBaseDir() = File(System.getProperty("user.home"), ".graffiti") | ||
|
||
private fun getTokenPath(): File { | ||
val baseDir = getTokenBaseDir() | ||
baseDir.mkdirs() | ||
return File(baseDir, "token") | ||
} | ||
private fun validateToken(token: String): Boolean = try { | ||
UUID.fromString(token).version() == 4 | ||
} catch (ignored: IllegalArgumentException){ | ||
false | ||
} | ||
|
||
private fun getTokenFromFile(): String? { | ||
val tokenFile = getTokenPath() | ||
if (!tokenFile.exists()) return null | ||
val token = tokenFile.readText().trim() | ||
return when { | ||
token.isEmpty() -> { | ||
logger.info("token file is empty!") | ||
null | ||
} | ||
!validateToken(token) -> { | ||
logger.info("Token is not valid uuid v4: $token") | ||
null | ||
} | ||
else -> { | ||
token | ||
} | ||
} | ||
} | ||
|
||
fun saveTokenToFile(token: String) { | ||
getTokenPath().writeText(token) | ||
} | ||
|
||
fun getTokenOrElse(askForToken: () -> String?): String? { | ||
val fileToken = getTokenFromFile() | ||
if (fileToken != null) return fileToken | ||
|
||
val inputToken = askForToken() | ||
return when { | ||
inputToken == null -> { | ||
logger.info("Authentication canceled") | ||
null | ||
} | ||
!validateToken(inputToken) -> { | ||
logger.info("Token is not valid uuid v4: $inputToken") | ||
null | ||
} | ||
else -> { | ||
saveTokenToFile(inputToken) | ||
inputToken | ||
} | ||
} | ||
} |
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 @@ | ||
../jeb/authentication.py |
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
Oops, something went wrong.