2626 Created time.Time `json:"created"`
2727 CreatedBy string `json:"createdBy"`
2828 Expires time.Time `json:"expires"`
29- Id string `json:"id"`
29+ ID string `json:"id"`
3030 RedirectURL string `json:"redirectURL"`
3131 URL string `json:"url"`
3232 }
@@ -52,7 +52,7 @@ func (c *AdminContext) GetLoginHistory() ([]*LoginHistory, error) {
5252 }
5353
5454 if len (loginHistory ) == 0 {
55- return nil , fmt . Errorf ("no login history found" )
55+ return nil , errors . New ("no login history found" )
5656 }
5757
5858 return loginHistory , nil
@@ -69,7 +69,7 @@ func (c *UserContext) GetLoginURLs() ([]*LoginKeyURL, error) {
6969}
7070
7171// GetMyUsername returns the current user's username. This is particularly useful when logging in as another user, as it
72- // trims the admin/reseller username automatically
72+ // trims the admin/reseller username automatically.
7373func (c * UserContext ) GetMyUsername () string {
7474 // If the user is logged in via reseller, we need to remove the reseller username from the context's username.
7575 if strings .Contains (c .credentials .username , "|" ) {
@@ -79,6 +79,7 @@ func (c *UserContext) GetMyUsername() string {
7979 return c .credentials .username
8080}
8181
82+ // Login checks whether the configured credentials work against the configured API.
8283func (c * UserContext ) Login () error {
8384 var response apiGenericResponse
8485
@@ -94,7 +95,7 @@ func (c *UserContext) Login() error {
9495}
9596
9697// LoginAsAdmin verifies the provided credentials against the DA API, then returns an admin-level context.
97- // The passkey can either be the user's password, or a login key
98+ // The passkey can either be the user's password, or a login key.
9899func (a * API ) LoginAsAdmin (username string , passkey string ) (* AdminContext , error ) {
99100 userCtx , err := a .login (username , passkey )
100101 if err != nil {
@@ -115,7 +116,7 @@ func (a *API) LoginAsAdmin(username string, passkey string) (*AdminContext, erro
115116}
116117
117118// LoginAsReseller verifies the provided credentials against the DA API, then returns a reseller-level context.
118- // The passkey can either be the user's password, or a login key
119+ // The passkey can either be the user's password, or a login key.
119120func (a * API ) LoginAsReseller (username string , passkey string ) (* ResellerContext , error ) {
120121 userCtx , err := a .login (username , passkey )
121122 if err != nil {
@@ -134,7 +135,7 @@ func (a *API) LoginAsReseller(username string, passkey string) (*ResellerContext
134135}
135136
136137// LoginAsUser verifies the provided credentials against the DA API, then returns a user-level context.
137- // The passkey can either be the user's password, or a login key
138+ // The passkey can either be the user's password, or a login key.
138139func (a * API ) LoginAsUser (username string , passkey string ) (* UserContext , error ) {
139140 userCtx , err := a .login (username , passkey )
140141 if err != nil {
@@ -148,14 +149,18 @@ func (a *API) LoginAsUser(username string, passkey string) (*UserContext, error)
148149 return userCtx , nil
149150}
150151
152+ // LoginAsMyReseller logs the current admin into the given reseller's account.
151153func (c * AdminContext ) LoginAsMyReseller (username string ) (* ResellerContext , error ) {
152154 return c .api .LoginAsReseller (c .credentials .username + "|" + username , c .credentials .passkey )
153155}
154156
157+ // LoginAsMyUser logs the current reseller into the given user's account.
155158func (c * ResellerContext ) LoginAsMyUser (username string ) (* UserContext , error ) {
156159 return c .api .LoginAsUser (c .credentials .username + "|" + username , c .credentials .passkey )
157160}
158161
162+ // login sets up the user context's cookie jar, verifies that the credentials work against the API, and pulls the user's
163+ // config.
159164func (a * API ) login (username string , passkey string ) (* UserContext , error ) {
160165 jar , err := cookiejar .New (nil )
161166 if err != nil {
0 commit comments