Expose user login functionality

This commit is contained in:
Tom Wiesing 2023-01-07 14:31:20 +01:00
parent 97f5ac7e1a
commit 8a5b066839
No known key found for this signature in database
8 changed files with 246 additions and 8 deletions

View file

@ -36,10 +36,25 @@ var errLoginUnknownError = errors.New("Login: Unknown Error")
// Login generates a login link for the user with the given username
func (u *Users) Login(ctx context.Context, server *phpx.Server, username string) (dest *url.URL, err error) {
return u.LoginWithOpt(ctx, server, username, LoginOptions{
Destination: "/",
CreateIfMissing: false,
GrantAdminRole: false,
})
}
type LoginOptions struct {
Destination string
CreateIfMissing bool
GrantAdminRole bool
}
// LoginOrCreate generates a login link for the user with the given username and options
func (u *Users) LoginWithOpt(ctx context.Context, server *phpx.Server, username string, opts LoginOptions) (dest *url.URL, err error) {
// generate a (relative) link
var path string
err = u.Dependencies.PHP.ExecScript(ctx, server, &path, usersPHP, "get_login_link", username)
err = u.Dependencies.PHP.ExecScript(ctx, server, &path, usersPHP, "get_login_link", username, opts.Destination, opts.CreateIfMissing, opts.GrantAdminRole)
// if something went wrong, return
if err != nil {