Exemplo n.º 1
0
// get user if key exist in session
func GetUserFromSession(user *User, sess session.SessionStore) bool {
	if id, ok := sess.Get("auth_user_id").(int64); ok && id > 0 {
		*user = User{Id: id}
		if user.Read() == nil {
			return true
		}
	}

	return false
}
Exemplo n.º 2
0
func DoAuth(sess session.SessionStore) {
	if utils.IsPassedAuth() {
		sess.Set(utils.SessAuth, "ok")
		utils.UpdateSolarMapItem(utils.SessAuth, "ok")
		fmt.Println("AUTH OK!")
		utils.WriteDebugLog("AUTH OK!")
	} else {
		sess.Set(utils.SessAuth, "none")
		utils.UpdateSolarMapItem(utils.SessAuth, "none")
	}
}
Exemplo n.º 3
0
func DoSetSN(sn string, sess session.SessionStore) {
	if len(sn) == snlength {
		// sn works
		if err := getChipSNAtString(sn); err == nil {
			utils.SetChipSNArrayItem(ChipSN)
			utils.PrintChipSN()
			sess.Set(utils.SessAuth, "sn")
			utils.UpdateSolarMapItem(utils.SessAuth, "sn")
		}
	}
}
Exemplo n.º 4
0
// Handles verification of account email based on validationKey
func VerifyEmail(w http.ResponseWriter, r *http.Request) {
	validationKey := strings.Split(r.RequestURI, "/")[2]
	stmt, _ := db.Prepare("select username, email, password from signup where validationKey = ?")
	var username string
	var email string
	var password string
	res := stmt.QueryRow(validationKey)
	err := res.Scan(&username, &email, &password)
	if err != nil {
		http.Redirect(w, r, "/validationFailed", 302)
	}

	stmt, _ = db.Prepare("insert into users (username, email, password) values (?,?,?)")
	row, err := stmt.Exec(username, email, password)
	if err == nil {
		id64, _ := row.LastInsertId()
		id := int(id64)
		// Login user and delete signup record
		var sess session.SessionStore
		sessionCookie, err := r.Cookie("session_id")
		if err == nil {
			sess, _ = globalSessions.GetSessionStore(sessionCookie.Value)
		} else {
			sess, _ = globalSessions.SessionStart(w, r)
		}
		defer sess.SessionRelease(w)

		_ = sess.Set("user_id", id)
		_ = sess.Set("username", username)
		setUserCookies(w, id, sess.SessionID())
		saveSession(w, r, sess.SessionID(), id)
		addRemoteAddress(r, id)
		db.Prepare("delete from signup where validationKey = ?")
		db.Exec(validationKey)
		http.Redirect(w, r, "/", 302)
	}
}
Exemplo n.º 5
0
func GetUserIdFromSession(sess session.SessionStore) int {
	if id, ok := sess.Get("auth_user_id").(int); ok && id > 0 {
		return id
	}
	return 0
}
Exemplo n.º 6
0
func MarkNotLogin(sess session.SessionStore) {
	sess.Delete(_session_login_flag)
}
Exemplo n.º 7
0
func MarkLogin(sess session.SessionStore) {
	sess.Set(_session_login_flag, _session_login_flag)
}