mirror of
https://github.com/gravitl/netmaker.git
synced 2026-01-07 03:14:03 +08:00
add invited user via oauth signup automatically
This commit is contained in:
parent
0fc9a181fd
commit
12acada4a1
4 changed files with 126 additions and 32 deletions
|
|
@ -71,23 +71,47 @@ func handleAzureCallback(w http.ResponseWriter, r *http.Request) {
|
|||
handleOauthUserNotAllowedToSignUp(w)
|
||||
return
|
||||
}
|
||||
var inviteExists bool
|
||||
// check if invite exists for User
|
||||
_, err = logic.GetUserInvite(content.UserPrincipalName)
|
||||
if err == nil {
|
||||
inviteExists = true
|
||||
}
|
||||
// check if user approval is already pending
|
||||
if logic.IsPendingUser(content.UserPrincipalName) {
|
||||
if !inviteExists && logic.IsPendingUser(content.UserPrincipalName) {
|
||||
handleOauthUserSignUpApprovalPending(w)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = logic.GetUser(content.UserPrincipalName)
|
||||
if err != nil {
|
||||
if database.IsEmptyRecord(err) { // user must not exist, so try to make one
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.UserPrincipalName,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
if inviteExists {
|
||||
// create user
|
||||
var newPass, fetchErr = auth.FetchPassValue("")
|
||||
if fetchErr != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(fetchErr, "internal"))
|
||||
return
|
||||
}
|
||||
if err = logic.CreateUser(&models.User{
|
||||
UserName: content.UserPrincipalName,
|
||||
Password: newPass,
|
||||
}); err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
logic.DeletePendingUser(content.UserPrincipalName)
|
||||
} else {
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.UserPrincipalName,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
} else {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -71,23 +71,46 @@ func handleGithubCallback(w http.ResponseWriter, r *http.Request) {
|
|||
handleOauthUserNotAllowedToSignUp(w)
|
||||
return
|
||||
}
|
||||
var inviteExists bool
|
||||
// check if invite exists for User
|
||||
_, err = logic.GetUserInvite(content.Login)
|
||||
if err == nil {
|
||||
inviteExists = true
|
||||
}
|
||||
// check if user approval is already pending
|
||||
if logic.IsPendingUser(content.Login) {
|
||||
if !inviteExists && logic.IsPendingUser(content.Login) {
|
||||
handleOauthUserSignUpApprovalPending(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.Login)
|
||||
if err != nil {
|
||||
if database.IsEmptyRecord(err) { // user must not exist, so try to make one
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.Login,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
if inviteExists {
|
||||
// create user
|
||||
var newPass, fetchErr = auth.FetchPassValue("")
|
||||
if fetchErr != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(fetchErr, "internal"))
|
||||
return
|
||||
}
|
||||
if err = logic.CreateUser(&models.User{
|
||||
UserName: content.Login,
|
||||
Password: newPass,
|
||||
}); err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
logic.DeletePendingUser(content.Login)
|
||||
} else {
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.Login,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
} else {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -73,23 +73,47 @@ func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {
|
|||
handleOauthUserNotAllowedToSignUp(w)
|
||||
return
|
||||
}
|
||||
var inviteExists bool
|
||||
// check if invite exists for User
|
||||
_, err = logic.GetUserInvite(content.Email)
|
||||
if err == nil {
|
||||
inviteExists = true
|
||||
}
|
||||
// check if user approval is already pending
|
||||
if logic.IsPendingUser(content.Email) {
|
||||
if !inviteExists && logic.IsPendingUser(content.Email) {
|
||||
handleOauthUserSignUpApprovalPending(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.Email)
|
||||
if err != nil {
|
||||
if database.IsEmptyRecord(err) { // user must not exist, so try to make one
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.Email,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
if inviteExists {
|
||||
// create user
|
||||
var newPass, fetchErr = auth.FetchPassValue("")
|
||||
if fetchErr != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(fetchErr, "internal"))
|
||||
return
|
||||
}
|
||||
if err = logic.CreateUser(&models.User{
|
||||
UserName: content.Email,
|
||||
Password: newPass,
|
||||
}); err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
logic.DeletePendingUser(content.Email)
|
||||
} else {
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.Email,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
|
||||
} else {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -84,23 +84,46 @@ func handleOIDCCallback(w http.ResponseWriter, r *http.Request) {
|
|||
handleOauthUserNotAllowedToSignUp(w)
|
||||
return
|
||||
}
|
||||
var inviteExists bool
|
||||
// check if invite exists for User
|
||||
_, err = logic.GetUserInvite(content.Login)
|
||||
if err == nil {
|
||||
inviteExists = true
|
||||
}
|
||||
// check if user approval is already pending
|
||||
if logic.IsPendingUser(content.Email) {
|
||||
if !inviteExists && logic.IsPendingUser(content.Email) {
|
||||
handleOauthUserSignUpApprovalPending(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.Email)
|
||||
if err != nil {
|
||||
if database.IsEmptyRecord(err) { // user must not exist, so try to make one
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.Email,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
if inviteExists {
|
||||
// create user
|
||||
var newPass, fetchErr = auth.FetchPassValue("")
|
||||
if fetchErr != nil {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(fetchErr, "internal"))
|
||||
return
|
||||
}
|
||||
if err = logic.CreateUser(&models.User{
|
||||
UserName: content.Email,
|
||||
Password: newPass,
|
||||
}); err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
logic.DeletePendingUser(content.Email)
|
||||
} else {
|
||||
err = logic.InsertPendingUser(&models.User{
|
||||
UserName: content.Email,
|
||||
})
|
||||
if err != nil {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
}
|
||||
handleFirstTimeOauthUserSignUp(w)
|
||||
return
|
||||
} else {
|
||||
handleSomethingWentWrong(w)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue