Skip to content

Commit

Permalink
Updated variables names according to Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed Apr 24, 2016
1 parent c613dd8 commit 12aa41d
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 185 deletions.
2 changes: 1 addition & 1 deletion controller/about.go
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/josephspurrier/gowebapp/shared/view"
)

// Displays the About page
// AboutGET displays the About page
func AboutGET(w http.ResponseWriter, r *http.Request) {
// Display the view
v := view.New(r)
Expand Down
4 changes: 2 additions & 2 deletions controller/index.go
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/josephspurrier/gowebapp/shared/view"
)

// Displays the default home page
func Index(w http.ResponseWriter, r *http.Request) {
// IndexGET displays the home page
func IndexGET(w http.ResponseWriter, r *http.Request) {
// Get session
session := session.Instance(r)

Expand Down
11 changes: 7 additions & 4 deletions controller/login.go
Expand Up @@ -29,6 +29,7 @@ func loginAttempt(sess *sessions.Session) {
}
}

// LoginGET displays the login page
func LoginGET(w http.ResponseWriter, r *http.Request) {
// Get session
sess := session.Instance(r)
Expand All @@ -42,6 +43,7 @@ func LoginGET(w http.ResponseWriter, r *http.Request) {
v.Render(w)
}

// LoginPOST handles the login form submission
func LoginPOST(w http.ResponseWriter, r *http.Request) {
// Get session
sess := session.Instance(r)
Expand Down Expand Up @@ -81,17 +83,17 @@ func LoginPOST(w http.ResponseWriter, r *http.Request) {
sess.AddFlash(view.Flash{"There was an error. Please try again later.", view.FlashError})
sess.Save(r, w)
} else if passhash.MatchString(result.Password, password) {
if result.Status_id != 1 {
if result.StatusID != 1 {
// User inactive and display inactive message
sess.AddFlash(view.Flash{"Account is inactive so login is disabled.", view.FlashNotice})
sess.Save(r, w)
} else {
// Login successfully
session.Empty(sess)
sess.AddFlash(view.Flash{"Login successful!", view.FlashSuccess})
sess.Values["id"] = result.ID()
sess.Values["id"] = result.UserID()
sess.Values["email"] = email
sess.Values["first_name"] = result.First_name
sess.Values["first_name"] = result.FirstName
sess.Save(r, w)
http.Redirect(w, r, "/", http.StatusFound)
return
Expand All @@ -106,7 +108,8 @@ func LoginPOST(w http.ResponseWriter, r *http.Request) {
LoginGET(w, r)
}

func Logout(w http.ResponseWriter, r *http.Request) {
// LogoutGET clears the session and logs the user out
func LogoutGET(w http.ResponseWriter, r *http.Request) {
// Get session
sess := session.Instance(r)

Expand Down
8 changes: 5 additions & 3 deletions controller/register.go
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/josephspurrier/csrfbanana"
)

// RegisterGET displays the register page
func RegisterGET(w http.ResponseWriter, r *http.Request) {
// Get session
sess := session.Instance(r)
Expand All @@ -26,6 +27,7 @@ func RegisterGET(w http.ResponseWriter, r *http.Request) {
v.Render(w)
}

// RegisterPOST handles the registration form submission
func RegisterPOST(w http.ResponseWriter, r *http.Request) {
// Get session
sess := session.Instance(r)
Expand Down Expand Up @@ -54,8 +56,8 @@ func RegisterPOST(w http.ResponseWriter, r *http.Request) {
}

// Get form values
first_name := r.FormValue("first_name")
last_name := r.FormValue("last_name")
firstName := r.FormValue("first_name")
lastName := r.FormValue("last_name")
email := r.FormValue("email")
password, errp := passhash.HashString(r.FormValue("password"))

Expand All @@ -72,7 +74,7 @@ func RegisterPOST(w http.ResponseWriter, r *http.Request) {
_, err := model.UserByEmail(email)

if err == model.ErrNoResult { // If success (no user exists with that email)
ex := model.UserCreate(first_name, last_name, email, password)
ex := model.UserCreate(firstName, lastName, email, password)
// Will only error if there is a problem with the query
if ex != nil {
log.Println(ex)
Expand Down
16 changes: 8 additions & 8 deletions gowebapp.go
Expand Up @@ -48,7 +48,7 @@ func main() {
view.LoadPlugins(
plugin.TagHelper(config.View),
plugin.NoEscape(),
recaptcha.RecaptchaPlugin())
recaptcha.Plugin())

// Start the listener
server.Run(route.LoadHTTP(), route.LoadHTTPS(), config.Server)
Expand All @@ -63,13 +63,13 @@ var config = &configuration{}

// configuration contains the application settings
type configuration struct {
Database database.DatabaseInfo `json:"Database"`
Email email.SMTPInfo `json:"Email"`
Recaptcha recaptcha.RecaptchaInfo `json:"Recaptcha"`
Server server.Server `json:"Server"`
Session session.Session `json:"Session"`
Template view.Template `json:"Template"`
View view.View `json:"View"`
Database database.Info `json:"Database"`
Email email.SMTPInfo `json:"Email"`
Recaptcha recaptcha.Info `json:"Recaptcha"`
Server server.Server `json:"Server"`
Session session.Session `json:"Session"`
Template view.Template `json:"Template"`
View view.View `json:"View"`
}

// ParseJSON unmarshals bytes to structs
Expand Down
49 changes: 26 additions & 23 deletions model/bolt/user.go
Expand Up @@ -15,25 +15,28 @@ import (

// User table contains the information for each user
type User struct {
ObjectId bson.ObjectId `bson:"_id"`
First_name string `db:"first_name" bson:"first_name"`
Last_name string `db:"last_name" bson:"last_name"`
Email string `db:"email" bson:"email"`
Password string `db:"password" bson:"password"`
Status_id uint8 `db:"status_id" bson:"status_id"`
Created_at time.Time `db:"created_at" bson:"created_at"`
Updated_at time.Time `db:"updated_at" bson:"updated_at"`
Deleted uint8 `db:"deleted" bson:"deleted"`
ObjectID bson.ObjectId `bson:"_id"`
FirstName string `db:"first_name" bson:"first_name"`
LastName string `db:"last_name" bson:"last_name"`
Email string `db:"email" bson:"email"`
Password string `db:"password" bson:"password"`
StatusID uint8 `db:"status_id" bson:"status_id"`
CreatedAt time.Time `db:"created_at" bson:"created_at"`
UpdatedAt time.Time `db:"updated_at" bson:"updated_at"`
Deleted uint8 `db:"deleted" bson:"deleted"`
}

var (
ErrCode = errors.New("Case statement in code is not correct.")
ErrNoResult = errors.New("Result not found.")
// ErrCode is a config or an internal error
ErrCode = errors.New("Case statement in code is not correct.")
// ErrNoResult is a not results error
ErrNoResult = errors.New("Result not found.")
// ErrUnavailable is a database not available error
ErrUnavailable = errors.New("Database is unavailable.")
)

// Id returns the user id
func (u *User) ID() string {
// UserID returns the user id
func (u *User) UserID() string {
return u.ObjectId.Hex()
}

Expand All @@ -57,21 +60,21 @@ func UserByEmail(email string) (User, error) {
}

// UserCreate creates user
func UserCreate(first_name, last_name, email, password string) error {
func UserCreate(firstName, lastName, email, password string) error {
var err error

now := time.Now()

user := &User{
ObjectId: bson.NewObjectId(),
First_name: first_name,
Last_name: last_name,
Email: email,
Password: password,
Status_id: 1,
Created_at: now,
Updated_at: now,
Deleted: 0,
ObjectID: bson.NewObjectId(),
FirstName: firstName,
LastName: lastName,
Email: email,
Password: password,
StatusID: 1,
CreatedAt: now,
UpdatedAt: now,
Deleted: 0,
}

err = database.Update("user", user.Email, &user)
Expand Down
49 changes: 26 additions & 23 deletions model/mongo/user.go
Expand Up @@ -16,25 +16,28 @@ import (

// User table contains the information for each user
type User struct {
ObjectId bson.ObjectId `bson:"_id"`
First_name string `db:"first_name" bson:"first_name"`
Last_name string `db:"last_name" bson:"last_name"`
Email string `db:"email" bson:"email"`
Password string `db:"password" bson:"password"`
Status_id uint8 `db:"status_id" bson:"status_id"`
Created_at time.Time `db:"created_at" bson:"created_at"`
Updated_at time.Time `db:"updated_at" bson:"updated_at"`
Deleted uint8 `db:"deleted" bson:"deleted"`
ObjectID bson.ObjectId `bson:"_id"`
FirstName string `db:"first_name" bson:"first_name"`
LastName string `db:"last_name" bson:"last_name"`
Email string `db:"email" bson:"email"`
Password string `db:"password" bson:"password"`
StatusID uint8 `db:"status_id" bson:"status_id"`
CreatedAt time.Time `db:"created_at" bson:"created_at"`
UpdatedAt time.Time `db:"updated_at" bson:"updated_at"`
Deleted uint8 `db:"deleted" bson:"deleted"`
}

var (
ErrCode = errors.New("Case statement in code is not correct.")
ErrNoResult = errors.New("Result not found.")
// ErrCode is a config or an internal error
ErrCode = errors.New("Case statement in code is not correct.")
// ErrNoResult is a not results error
ErrNoResult = errors.New("Result not found.")
// ErrUnavailable is a database not available error
ErrUnavailable = errors.New("Database is unavailable.")
)

// Id returns the user id
func (u *User) ID() string {
// UserID returns the user id
func (u *User) UserID() string {
return u.ObjectId.Hex()
}

Expand Down Expand Up @@ -66,7 +69,7 @@ func UserByEmail(email string) (User, error) {
}

// UserCreate creates user
func UserCreate(first_name, last_name, email, password string) error {
func UserCreate(firstName, lastName, email, password string) error {
var err error

now := time.Now()
Expand All @@ -77,15 +80,15 @@ func UserCreate(first_name, last_name, email, password string) error {
c := session.DB(database.ReadConfig().MongoDB.Database).C("user")

user := &User{
ObjectId: bson.NewObjectId(),
First_name: first_name,
Last_name: last_name,
Email: email,
Password: password,
Status_id: 1,
Created_at: now,
Updated_at: now,
Deleted: 0,
ObjectID: bson.NewObjectId(),
FirstName: firstName,
LastName: lastName,
Email: email,
Password: password,
StatusID: 1,
CreatedAt: now,
UpdatedAt: now,
Deleted: 0,
}
err = c.Insert(user)
} else {
Expand Down
51 changes: 27 additions & 24 deletions model/sql/user.go
Expand Up @@ -15,34 +15,37 @@ import (

// User table contains the information for each user
type User struct {
Id uint32 `db:"id"`
First_name string `db:"first_name"`
Last_name string `db:"last_name"`
Email string `db:"email"`
Password string `db:"password"`
Status_id uint8 `db:"status_id"`
Created_at time.Time `db:"created_at"`
Updated_at time.Time `db:"updated_at"`
Deleted uint8 `db:"deleted"`
ID uint32 `db:"id"`
FirstName string `db:"first_name"`
LastName string `db:"last_name"`
Email string `db:"email"`
Password string `db:"password"`
StatusID uint8 `db:"status_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
Deleted uint8 `db:"deleted"`
}

// User_status table contains every possible user status (active/inactive)
type User_status struct {
Id uint8 `db:"id"`
Status string `db:"status"`
Created_at time.Time `db:"created_at"`
Updated_at time.Time `db:"updated_at"`
Deleted uint8 `db:"deleted"`
// UserStatus table contains every possible user status (active/inactive)
type UserStatus struct {
ID uint8 `db:"id"`
Status string `db:"status"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
Deleted uint8 `db:"deleted"`
}

var (
ErrCode = errors.New("Case statement in code is not correct.")
ErrNoResult = errors.New("Result not found.")
// ErrCode is a config or an internal error
ErrCode = errors.New("Case statement in code is not correct.")
// ErrNoResult is a not results error
ErrNoResult = errors.New("Result not found.")
// ErrUnavailable is a database not available error
ErrUnavailable = errors.New("Database is unavailable.")
)

// Id returns the user id
func (u *User) ID() string {
// UserID returns the user id
func (u *User) UserID() string {
return fmt.Sprintf("%v", u.Id)
}

Expand All @@ -62,15 +65,15 @@ func UserByEmail(email string) (User, error) {
return result, err
}

// UserIdByEmail gets user id from email
func UserIdByEmail(email string) (User, error) {
// UserIDByEmail gets user id from email
func UserIDByEmail(email string) (User, error) {
result := User{}
err := database.Sql.Get(&result, "SELECT id FROM user WHERE email = ? LIMIT 1", email)
return result, err
}

// UserCreate creates user
func UserCreate(first_name, last_name, email, password string) error {
_, err := database.Sql.Exec("INSERT INTO user (first_name, last_name, email, password) VALUES (?,?,?,?)", first_name, last_name, email, password)
func UserCreate(firstName, lastName, email, password string) error {
_, err := database.Sql.Exec("INSERT INTO user (first_name, last_name, email, password) VALUES (?,?,?,?)", firstName, lastName, email, password)
return err
}

0 comments on commit 12aa41d

Please sign in to comment.