Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Github & Gitea OAuth provider #13

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Include HTML buttons
  • Loading branch information
thomiceli committed Apr 17, 2023
commit 2d42cf798c1ed35cc6fa61c6dd30ae34afc00aed
2 changes: 1 addition & 1 deletion internal/web/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func oauthCallback(ctx echo.Context) error {

if err = userDB.Create(); err != nil {
if models.IsUniqueConstraintViolation(err) {
addFlash(ctx, "Username "+user.NickName+" already exists in opengist", "error")
addFlash(ctx, "Username "+user.NickName+" already exists in Opengist", "error")
return redirect(ctx, "/login")
}

Expand Down
3 changes: 3 additions & 0 deletions internal/web/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func dataInit(next echo.HandlerFunc) echo.HandlerFunc {
}
setData(ctx, "signupDisabled", disableSignup == "1")

setData(ctx, "githubOauth", config.C.GithubClientKey != "" && config.C.GithubSecret != "")
setData(ctx, "giteaOauth", config.C.GiteaClientKey != "" && config.C.GiteaSecret != "")

return next(ctx)
}
}
Expand Down
19 changes: 19 additions & 0 deletions templates/pages/auth_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ <h1 class="text-2xl font-bold leading-tight text-slate-300">
{{ end }}
{{ .csrfHtml }}
</form>

<div class="relative my-4">
<div class="absolute inset-0 flex items-center" aria-hidden="true">
<div class="w-full border-t border-gray-700"></div>
</div>
</div>
<br />
<div class="">
{{ if .githubOauth }}
<a href="/oauth/github" class="block w-full mb-2 text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Continue with GitHub account
</a>
{{ end }}
{{ if .giteaOauth }}
<a href="/oauth/gitea" class="block w-full mb-2 text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Continue with Gitea account
</a>
{{ end }}
</div>
</div>
</div>
</div>
Expand Down
48 changes: 28 additions & 20 deletions templates/pages/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1 class="text-2xl font-bold leading-tight">Settings</h1>
</header>
<main>
<div class="space-y-4">
<div class="sm:grid grid-cols-3 gap-x-4 md:gap-x-8">
<div class="sm:grid {{ if or .githubOauth .giteaOauth }}grid-cols-3{{else}}grid-cols-2{{end}} gap-x-4 md:gap-x-8">
<div class="w-full">
<div class="bg-gray-900 rounded-md border border-1 border-gray-700 py-8 px-4 shadow sm:rounded-lg sm:px-10">
<h2 class="text-md font-bold text-slate-300">
Expand All @@ -27,34 +27,42 @@ <h3 class="text-sm text-gray-400 italic mb-4">
</form>
</div>
</div>
{{ if or .githubOauth .giteaOauth }}
<div class="w-full">
<div class="bg-gray-900 rounded-md border border-1 border-gray-700 py-8 px-4 shadow sm:rounded-lg sm:px-10">
<h2 class="text-md font-bold text-slate-300 mb-2">
Link accounts
</h2>
<div class="gap-y-2">
{{ if .userLogged.GithubID }}
<a href="/oauth/github" class="block w-full mb-2 text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Unlink GitHub account
</a>
{{ else }}
<a href="/oauth/github" class="block w-full mb-2 text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Link GitHub account
</a>
{{ end }}

{{ if .userLogged.GiteaID }}
<a href="/oauth/gitea" class="block w-full text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Unlink Gitea account
</a>
{{ else }}
<a href="/oauth/gitea" class="block w-full text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Link Gitea account
</a>
{{ end }}
{{ if .githubOauth }}
{{ if .userLogged.GithubID }}
<a href="/oauth/github" class="block w-full mb-2 text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Unlink GitHub account
</a>
{{ else }}
<a href="/oauth/github" class="block w-full mb-2 text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Link GitHub account
</a>
{{ end }}
{{ end }}

{{ if .giteaOauth }}
{{ if .userLogged.GiteaID }}
<a href="/oauth/gitea" class="block w-full text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Unlink Gitea account
</a>
{{ else }}
<a href="/oauth/gitea" class="block w-full text-center whitespace-nowrap text-slate-300{{ if .syncReposFromFS }} text-slate-500 cursor-not-allowed {{ end }}rounded border border-gray-600 bg-gray-800 px-2.5 py-2 text-xs font-medium text-white shadow-sm hover:bg-gray-700 hover:border-gray-500 hover:text-slate-300 focus:outline-none focus:ring-1 focus:border-primary-500 focus:ring-primary-500 leading-3">
Link Gitea account
</a>
{{ end }}
{{ end }}

</div>
</div>
</div>
{{ end }}
<div class="w-full">
<div class="bg-gray-900 rounded-md border border-1 border-gray-700 py-8 px-4 shadow sm:rounded-lg sm:px-10">
<h2 class="text-md font-bold text-slate-300">
Expand All @@ -68,7 +76,7 @@ <h2 class="text-md font-bold text-slate-300">
</div>
</div>
</div>
<div class="sm:grid grid-cols-2 gap-x-4 md:gap-x-16">
<div class="sm:grid grid-cols-2 gap-x-4 md:gap-x-8">
<div class="w-full">
<div class="bg-gray-900 rounded-md border border-1 border-gray-700 py-8 px-4 shadow sm:rounded-lg sm:px-10">
<h2 class="text-md font-bold text-slate-300">
Expand Down