Skip to content

Commit f432127

Browse files
committed
forgot to commit migration
1 parent 22f0fa7 commit f432127

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

cli/usercreate.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414

1515
func (r *RootCmd) userCreate() *clibase.Cmd {
1616
var (
17-
email string
18-
username string
19-
password string
17+
email string
18+
username string
19+
password string
20+
disableLogin bool
2021
)
2122
client := new(codersdk.Client)
2223
cmd := &clibase.Cmd{
@@ -53,7 +54,7 @@ func (r *RootCmd) userCreate() *clibase.Cmd {
5354
return err
5455
}
5556
}
56-
if password == "" {
57+
if password == "" && !disableLogin {
5758
password, err = cryptorand.StringCharset(cryptorand.Human, 20)
5859
if err != nil {
5960
return err
@@ -65,10 +66,16 @@ func (r *RootCmd) userCreate() *clibase.Cmd {
6566
Username: username,
6667
Password: password,
6768
OrganizationID: organization.ID,
69+
DisableLogin: disableLogin,
6870
})
6971
if err != nil {
7072
return err
7173
}
74+
authenticationMethod := `Your password is: ` + cliui.DefaultStyles.Field.Render(password)
75+
if disableLogin {
76+
authenticationMethod = "Login has been disabled for this user. Contact your administrator to authenticate."
77+
}
78+
7279
_, _ = fmt.Fprintln(inv.Stderr, `A new user has been created!
7380
Share the instructions below to get them started.
7481
`+cliui.DefaultStyles.Placeholder.Render("—————————————————————————————————————————————————")+`
@@ -78,7 +85,7 @@ https://github.com/coder/coder/releases
7885
Run `+cliui.DefaultStyles.Code.Render("coder login "+client.URL.String())+` to authenticate.
7986
8087
Your email is: `+cliui.DefaultStyles.Field.Render(email)+`
81-
Your password is: `+cliui.DefaultStyles.Field.Render(password)+`
88+
`+authenticationMethod+`
8289
8390
Create a workspace `+cliui.DefaultStyles.Code.Render("coder create")+`!`)
8491
return nil
@@ -103,6 +110,12 @@ Create a workspace `+cliui.DefaultStyles.Code.Render("coder create")+`!`)
103110
Description: "Specifies a password for the new user.",
104111
Value: clibase.StringOf(&password),
105112
},
113+
{
114+
Flag: "disable-login",
115+
Description: "Disabling login for a user prevents the user from authenticating themselves via a login. Authentication would require an api keys/token. " +
116+
"Be careful when using this flag as it can lock the user out of their account.",
117+
Value: clibase.BoolOf(&disableLogin),
118+
},
106119
}
107120
return cmd
108121
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
2+
-- EXISTS".
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TYPE login_type ADD VALUE IF NOT EXISTS 'none';
2+
3+
COMMENT ON TYPE login_type IS 'Specifies the method of authentication. "none" is a special case in which no authentication method is allowed.';

codersdk/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type CreateFirstUserResponse struct {
6868
type CreateUserRequest struct {
6969
Email string `json:"email" validate:"required,email" format:"email"`
7070
Username string `json:"username" validate:"required,username"`
71-
Password string `json:"password" validate:"required"`
71+
Password string `json:"password" validate:"required_if=DisableLogin false"`
7272
// DisableLogin sets the user's login type to 'none'. This prevents the user
7373
// from being able to use a password or any other authentication method to login.
7474
DisableLogin bool `json:"disable_login"`

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export interface CreateUserRequest {
223223
readonly email: string
224224
readonly username: string
225225
readonly password: string
226+
readonly disable_login: boolean
226227
readonly organization_id: string
227228
}
228229

site/src/components/CreateUserForm/CreateUserForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const CreateUserForm: FC<
5050
password: "",
5151
username: "",
5252
organization_id: myOrgId,
53+
disable_login: false,
5354
},
5455
validationSchema,
5556
onSubmit,

0 commit comments

Comments
 (0)