Esempio n. 1
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")
		}
	}
}
Esempio 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")
	}
}
Esempio n. 3
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)
	}
}
Esempio n. 4
0
func MarkLogin(sess session.SessionStore) {
	sess.Set(_session_login_flag, _session_login_flag)
}