returnnil,impart.HTTPError{http.StatusBadRequest,"A username is required."}
}
ifsignup.Pass==""{
returnnil,impart.HTTPError{http.StatusBadRequest,"A password is required."}
}
vardesiredUsernamestring
ifsignup.Normalize{
// With this option we simply conform the username to what we expect
// without complaining. Since they might've done something funny, like
// enter: write.as/Way Out There, we'll use their raw input for the new
// collection name and sanitize for the slug / username.
desiredUsername=signup.Alias
signup.Alias=getSlug(signup.Alias,"")
}
if!author.IsValidUsername(app.cfg,signup.Alias){
// Ensure the username is syntactically correct.
returnnil,impart.HTTPError{http.StatusPreconditionFailed,"Username is reserved or isn't valid. It must be at least 3 characters long, and can only include letters, numbers, and hyphens."}
log.Error("Admin reset attempt",`Someone just tried to reset the password for an admin (ID %d - %s). IP address: %s`,u.ID,u.Username,ip)
returnreturnLoc
}
ifu.Email.String==""{
err:=impart.HTTPError{http.StatusPreconditionFailed,"User doesn't have an email address. Please contact us ("+app.cfg.App.Host+"/contact) to reset your password."}
addSessionFlash(app,w,r,err.Message,nil)
returnreturnLoc
}
ifisSet,_:=app.db.IsUserPassSet(u.ID);!isSet{
err=loginViaEmail(app,u.Username,"/me/settings")
iferr!=nil{
returnerr
}
addSessionFlash(app,w,r,"We've emailed you a link to log in with.",nil)
footerPara:="Didn't request this password reset? Your account is still safe, and you can safely ignore this email."
plainMsg:=fmt.Sprintf("We received a request to reset your password on %s. Please click the following link to continue (or copy and paste it into your browser): %s/reset?t=%s\n\n%s",app.cfg.App.SiteName,app.cfg.App.Host,token,footerPara)
m:=mailgun.NewMessage(app.cfg.App.SiteName+" <noreply-password@"+app.cfg.Email.Domain+">","Reset Your "+app.cfg.App.SiteName+" Password",plainMsg,fmt.Sprintf("<%s>",toEmail))
footerPara:="This link will only work once and expires in 15 minutes. Didn't ask us to log in? You can safely ignore this email."
plainMsg:=fmt.Sprintf("Log in to %s here: %s/login?to=%s&with=%s\n\n%s",app.cfg.App.SiteName,app.cfg.App.Host,redirectTo,t,footerPara)
m:=mailgun.NewMessage(app.cfg.App.SiteName+" <noreply-login@"+app.cfg.Email.Domain+">","Log in to "+app.cfg.App.SiteName,plainMsg,fmt.Sprintf("<%s>",toEmail))