12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package actions
- import (
- "database/sql"
- _ "github.com/go-sql-driver/mysql"
- utils "golang-fave/engine/wrapper/utils"
- )
- func (this *Action) Action_signin() {
- if err := this.use_database(); err != nil {
- this.msg_error(err.Error())
- return
- } else {
- defer this.db.Close()
- }
- pf_email := this.wrapper.R.FormValue("email")
- pf_password := this.wrapper.R.FormValue("password")
- if pf_email == "" {
- this.msg_error(`Please specify user email`)
- return
- }
- if !utils.EmailIsValid(pf_email) {
- this.msg_error(`Please specify correct user email`)
- return
- }
- if pf_password == "" {
- this.msg_error(`Please specify user password`)
- return
- }
- if this.wrapper.Session.GetIntDef("UserId", 0) > 0 {
- this.msg_error(`You already logined`)
- return
- }
- var user_id int
- err := this.db.QueryRow(
- "SELECT `id` FROM `users` WHERE `email` = ? and `password` = MD5(?) LIMIT 1;",
- pf_email, pf_password).Scan(&user_id)
- if err != nil && err != sql.ErrNoRows {
- this.msg_error(err.Error())
- return
- }
- if err == sql.ErrNoRows {
- this.msg_error(`Incorrect email or password`)
- return
- }
- // Save to current session
- this.wrapper.Session.SetInt("UserId", user_id)
- // Reload current page
- this.write(`window.location.reload(false);`)
- }
|