save username and append to deviceid in auth header
This commit is contained in:
parent
f1512dc80a
commit
ac1e57b32e
|
@ -65,6 +65,9 @@ function LoginFlow()
|
|||
goto start_login
|
||||
else
|
||||
print "A public user was selected with username=" + userSelected
|
||||
session.user.Update("name", userSelected)
|
||||
regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "")
|
||||
session.user.Update("friendlyName", regex.ReplaceAll(userSelected, ""))
|
||||
' save userid to session
|
||||
for each user in publicUsersNodes
|
||||
if user.name = userSelected
|
||||
|
@ -83,6 +86,7 @@ function LoginFlow()
|
|||
if currentUser = invalid
|
||||
print "Auth token is no longer valid - deleting token"
|
||||
unset_user_setting("token")
|
||||
unset_user_setting("username")
|
||||
else
|
||||
print "Success! Auth token is still valid"
|
||||
session.user.Login(currentUser)
|
||||
|
@ -124,16 +128,34 @@ function LoginFlow()
|
|||
print "Active user found in registry"
|
||||
session.user.Update("id", activeUser)
|
||||
|
||||
myUsername = get_user_setting("username")
|
||||
myAuthToken = get_user_setting("token")
|
||||
if isValid(myAuthToken)
|
||||
if isValid(myAuthToken) and isValid(myUsername)
|
||||
print "Auth token found in registry"
|
||||
session.user.Update("authToken", myAuthToken)
|
||||
session.user.Update("name", myUsername)
|
||||
regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "")
|
||||
session.user.Update("friendlyName", regex.ReplaceAll(myUsername, ""))
|
||||
print "Attempting to use API with auth token"
|
||||
currentUser = AboutMe()
|
||||
if currentUser = invalid
|
||||
print "Auth token is no longer valid - delete token and restart login flow"
|
||||
unset_user_setting("token")
|
||||
goto start_login
|
||||
print "Auth token is no longer valid"
|
||||
'Try to login without password. If the token is valid, we're done
|
||||
print "Attempting to login with no password"
|
||||
userData = get_token(userSelected, "")
|
||||
if isValid(userData)
|
||||
print "login success!"
|
||||
session.user.Login(userData)
|
||||
LoadUserPreferences()
|
||||
LoadUserAbilities()
|
||||
return true
|
||||
else
|
||||
print "Auth failed. Password required"
|
||||
print "delete token and restart login flow"
|
||||
unset_user_setting("token")
|
||||
unset_user_setting("username")
|
||||
goto start_login
|
||||
end if
|
||||
else
|
||||
print "Success! Auth token is still valid"
|
||||
session.user.Login(currentUser)
|
||||
|
@ -432,6 +454,7 @@ function CreateSigninGroup(user = "")
|
|||
' save credentials
|
||||
if checkbox.checkedState[0] = true
|
||||
set_user_setting("token", activeUser.token)
|
||||
set_user_setting("username", username.value)
|
||||
end if
|
||||
return "true"
|
||||
end if
|
||||
|
|
|
@ -203,14 +203,18 @@ function authRequest(request as object) as object
|
|||
|
||||
if m.global.session.user.id <> invalid
|
||||
auth = auth + ", UserId=" + QUOTE + m.global.session.user.id + QUOTE
|
||||
auth = auth + ", DeviceId=" + QUOTE + m.global.device.id + QUOTE
|
||||
if m.global.session.user.authToken <> invalid
|
||||
auth = auth + ", Token=" + QUOTE + m.global.session.user.authToken + QUOTE
|
||||
end if
|
||||
else
|
||||
auth = auth + ", DeviceId=" + QUOTE + m.global.device.uuid + QUOTE
|
||||
end if
|
||||
|
||||
if m.global.session.user <> invalid and m.global.session.user.friendlyName <> invalid
|
||||
auth = auth + ", DeviceId=" + QUOTE + m.global.device.id + m.global.session.user.friendlyName + QUOTE
|
||||
else
|
||||
auth = auth + ", DeviceId=" + QUOTE + m.global.device.id + QUOTE
|
||||
end if
|
||||
|
||||
if m.global.session.user.authToken <> invalid
|
||||
auth = auth + ", Token=" + QUOTE + m.global.session.user.authToken + QUOTE
|
||||
end if
|
||||
print auth
|
||||
request.AddHeader("Authorization", auth)
|
||||
return request
|
||||
end function
|
||||
|
|
|
@ -34,6 +34,7 @@ end function
|
|||
sub SignOut(deleteSavedEntry = true as boolean)
|
||||
if m.global.session.user.id <> invalid and deleteSavedEntry = true
|
||||
unset_user_setting("token")
|
||||
unset_user_setting("username")
|
||||
end if
|
||||
unset_setting("active_user")
|
||||
session.user.Logout()
|
||||
|
|
|
@ -12,7 +12,7 @@ function getDeviceCapabilities() as object
|
|||
"Photo"
|
||||
],
|
||||
"SupportedCommands": [],
|
||||
"SupportsPersistentIdentifier": false,
|
||||
"SupportsPersistentIdentifier": true,
|
||||
"SupportsMediaControl": false,
|
||||
"SupportsContentUploading": false,
|
||||
"SupportsSync": false,
|
||||
|
|
|
@ -137,6 +137,10 @@ namespace session
|
|||
tmpSession.AddReplace("user", userData.json.User)
|
||||
tmpSession.user.AddReplace("authToken", userData.json.AccessToken)
|
||||
end if
|
||||
' remove special characters from name
|
||||
regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "")
|
||||
friendlyName = regex.ReplaceAll(tmpSession.user.name, "")
|
||||
tmpSession.user.AddReplace("friendlyName", friendlyName)
|
||||
|
||||
tmpSession.user.AddReplace("settings", oldUserSettings)
|
||||
' update global user session
|
||||
|
@ -149,11 +153,13 @@ namespace session
|
|||
end for
|
||||
|
||||
if m.global.app.isDev
|
||||
print "m.global.session.user = ", m.global.session.user
|
||||
print "m.global.session.user.settings = ", m.global.session.user.settings
|
||||
end if
|
||||
|
||||
if m.global.session.user.settings["global.rememberme"]
|
||||
set_user_setting("token", tmpSession.user.authToken)
|
||||
set_user_setting("username", tmpSession.user.name)
|
||||
end if
|
||||
end sub
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user