MCPcopy Index your code
hub / github.com/dnote/dnote / Create

Method Create

pkg/server/controllers/users.go:108–139  ·  view source on GitHub ↗

Create handles register

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

106
107// Create handles register
108func (u *Users) Create(w http.ResponseWriter, r *http.Request) {
109 vd := getDataWithReferrer(r)
110
111 var form RegistrationForm
112 if err := parseForm(r, &form); err != nil {
113 handleHTMLError(w, r, err, "parsing form", u.NewView, vd)
114 return
115 }
116
117 vd.Yield["Email"] = form.Email
118
119 user, err := u.app.CreateUser(form.Email, form.Password, form.PasswordConfirmation)
120 if err != nil {
121 handleHTMLError(w, r, err, "creating user", u.NewView, vd)
122 return
123 }
124
125 session, err := u.app.SignIn(&user)
126 if err != nil {
127 handleHTMLError(w, r, err, "signing in a user", u.LoginView, vd)
128 return
129 }
130
131 if err := u.app.SendWelcomeEmail(form.Email); err != nil {
132 log.ErrorWrap(err, "sending welcome email")
133 }
134
135 setSessionCookie(w, session.Key, session.ExpiresAt)
136
137 dest := getPathOrReferrer("/", r)
138 http.Redirect(w, r, dest, http.StatusFound)
139}
140
141// LoginForm is the form data for log in
142type LoginForm struct {

Callers 5

CopyFileFunction · 0.80
GetEditorInputFunction · 0.80
TestGetTmpContentPathFunction · 0.80
CreateBookMethod · 0.80
CreateNoteMethod · 0.80

Calls 9

ErrorWrapFunction · 0.92
getDataWithReferrerFunction · 0.85
parseFormFunction · 0.85
handleHTMLErrorFunction · 0.85
setSessionCookieFunction · 0.85
getPathOrReferrerFunction · 0.85
CreateUserMethod · 0.80
SignInMethod · 0.80
SendWelcomeEmailMethod · 0.80

Tested by 1

TestGetTmpContentPathFunction · 0.64