Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosegala authored and eabili0 committed Oct 4, 2019
1 parent 2c2de3a commit 2e5c520
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ From the project root folder, fire the following commands to execute this projec
--base-ui-path ./web/ui/www \
--hydra-admin-url http://localhost:4445 \
--hydra-public-url http://localhost:4444 \
--public-url http://localhost:7070 \
--secret-key uhSunsodnsuBsdjsbds \
--log-level debug \
--scopes-file-path ./scopes.json \
Expand Down
5 changes: 3 additions & 2 deletions mail/confirmation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mail

import (
"fmt"
"github.com/labbsr0x/whisper/misc"
)

Expand All @@ -15,10 +16,10 @@ type emailConfirmationMailContent struct {
}

// GetEmailConfirmationMail render the mail for email confirmation
func GetEmailConfirmationMail(baseUIPath, secret, username, email, challenge string) Mail {
func GetEmailConfirmationMail(baseUIPath, secret, publicAddress, username, email, challenge string) Mail {
to := []string{email}
token := misc.GetEmailConfirmationToken(secret, username, challenge)
link := "http://localhost:7070/email-confirmation?token=" + token
link := fmt.Sprintf("%v/email-confirmation?token=%v", publicAddress, token)
page := emailConfirmationMailContent{Link: link, Username: username}
content := render(baseUIPath, emailConfirmationMail, &page)

Expand Down
2 changes: 1 addition & 1 deletion web/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (dapi *DefaultLoginAPI) LoginPOSTHandler() http.Handler {
userCredential := dapi.UserCredentialsDAO.CheckCredentials(loginRequest.Username, loginRequest.Password)

if !userCredential.EmailValidated {
dapi.Outbox <- mail.GetEmailConfirmationMail(dapi.BaseUIPath, dapi.SecretKey, userCredential.Username, userCredential.Email, loginRequest.Challenge)
dapi.Outbox <- mail.GetEmailConfirmationMail(dapi.BaseUIPath, dapi.SecretKey, dapi.PublicURL, userCredential.Username, userCredential.Email, loginRequest.Challenge)
gohtypes.Panic("This account email is not authenticated, an email was sent to you confirm your email", http.StatusUnauthorized)
}

Expand Down
2 changes: 1 addition & 1 deletion web/api/usercredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (dapi *DefaultUserCredentialsAPI) POSTHandler() http.Handler {
gohtypes.PanicIfError("Not possible to create user", http.StatusInternalServerError, err)
logrus.Infof("User created: %v", userID)

dapi.Outbox <- mail.GetEmailConfirmationMail(dapi.BaseUIPath, dapi.SecretKey, payload.Username, payload.Email, payload.Challenge)
dapi.Outbox <- mail.GetEmailConfirmationMail(dapi.BaseUIPath, dapi.SecretKey, dapi.PublicURL, payload.Username, payload.Email, payload.Challenge)

w.WriteHeader(http.StatusOK)
})
Expand Down
6 changes: 6 additions & 0 deletions web/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
port = "port"
hydraAdminURL = "hydra-admin-url"
hydraPublicURL = "hydra-public-url"
publicURL = "public-url"
logLevel = "log-level"
scopesFilePath = "scopes-file-path"
databaseURL = "database-url"
Expand All @@ -41,6 +42,7 @@ type Flags struct {
ScopesFilePath string
HydraAdminURL string
HydraPublicURL string
PublicURL string
DatabaseURL string
SecretKey string
MailUser string
Expand All @@ -64,6 +66,7 @@ func AddFlags(flags *pflag.FlagSet) {
flags.StringP(port, "p", "7070", "[optional] Custom port for accessing Whisper's services. Defaults to 7070")
flags.StringP(hydraAdminURL, "a", "", "Hydra Admin URL")
flags.StringP(hydraPublicURL, "o", "", "Hydra Public URL")
flags.StringP(publicURL, "", "", "Public URL for referencing in links")
flags.StringP(logLevel, "l", "info", "[optional] Sets the Log Level to one of seven (trace, debug, info, warn, error, fatal, panic). Defaults to info")
flags.StringP(scopesFilePath, "s", "", "Sets the path to the json file where the available scopes will be found")
flags.StringP(databaseURL, "d", "", "Sets the database url where user credential data will be stored")
Expand All @@ -83,6 +86,7 @@ func (b *WebBuilder) Init(v *viper.Viper, outbox chan<- mail.Mail) *WebBuilder {
flags.ScopesFilePath = v.GetString(scopesFilePath)
flags.HydraAdminURL = v.GetString(hydraAdminURL)
flags.HydraPublicURL = v.GetString(hydraPublicURL)
flags.PublicURL = v.GetString(publicURL)
flags.DatabaseURL = v.GetString(databaseURL)
flags.SecretKey = v.GetString(secretKey)
flags.MailUser = v.GetString(mailUser)
Expand All @@ -108,6 +112,7 @@ func (flags *Flags) check() {
haveEmptyRequiredFlags := flags.BaseUIPath == "" ||
flags.HydraAdminURL == "" ||
flags.HydraPublicURL == "" ||
flags.PublicURL == "" ||
flags.ScopesFilePath == "" ||
flags.SecretKey == "" ||
flags.DatabaseURL == "" ||
Expand All @@ -120,6 +125,7 @@ func (flags *Flags) check() {
baseUIPath,
hydraAdminURL,
hydraPublicURL,
publicURL,
scopesFilePath,
secretKey,
databaseURL,
Expand Down

0 comments on commit 2e5c520

Please sign in to comment.