當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Dbh.GetUserByEmail方法代碼示例

本文整理匯總了Golang中pixelrelay/db.Dbh.GetUserByEmail方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dbh.GetUserByEmail方法的具體用法?Golang Dbh.GetUserByEmail怎麽用?Golang Dbh.GetUserByEmail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pixelrelay/db.Dbh的用法示例。


在下文中一共展示了Dbh.GetUserByEmail方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: LoginPost

func LoginPost(lu forms.Login, session sessions.Session, r render.Render, dbh *db.Dbh) {
	errs := ValidateLogin(&lu)
	if len(errs) > 0 {
		log.Printf("errors: %+v\n", errs)
	}

	user := dbh.GetUserByEmail(lu.Email)

	match := auth.MatchPassword(lu.Password, user.Password, user.Salt)

	if match {
		sessionkey := SessionKey(user.Email, user.Password, user.Salt)

		session.Set("loggedin", "true")
		session.Set("uid", user.Id)
		session.Set("email", user.Email)
		session.Set("key", sessionkey)

		dbh.CreateSession(models.UserSession{UserId: user.Id, SessionKey: sessionkey, Active: true, Timestamp: time.Now().Unix()})

		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "albums"}, "/"), http.StatusFound)
		return
	}

	session.Set("flash", "Invalid Email or Password")

	r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "login"}, "/"), http.StatusFound)
}
開發者ID:szwork2013,項目名稱:gopixelrelay,代碼行數:28,代碼來源:login.go

示例2: SetupAdminPost

func SetupAdminPost(sa forms.SetupAdmin, args martini.Params, session sessions.Session, r render.Render, res http.ResponseWriter, dbh *db.Dbh) {
	errs := Validate(&sa)
	if len(errs) > 0 {
		fmt.Printf("%+v\n", errs)
	}

	v := session.Get("setup")
	if v != "true" {
		http.Error(res, "Unauthorized", http.StatusUnauthorized)
		return
	}

	user := dbh.GetUserByEmail(sa.Email)

	if user.Id > 0 {
		fmt.Println("user already exists")
		session.Set("uid", user.Id)
	}

	if user.Id == 0 {
		fmt.Println("id: 0")
		hash, salt, err := auth.EncryptPassword(sa.Password)
		if err != nil {
			fmt.Println("hash err: ", err)
		}
		newuser := models.User{Name: sa.Name, Email: sa.Email, Password: hash, Salt: salt, Timestamp: time.Now().Unix()}
		dbh.InsertUser(newuser)
		session.Set("uid", newuser.Id)
	}

	uid := session.Get("uid")

	fmt.Println("uid: ", uid)
	genform := utils.GenerateForm(&sa, "/setup", "POST", errs)
	r.HTML(200, "setup", genform)
}
開發者ID:szwork2013,項目名稱:gopixelrelay,代碼行數:36,代碼來源:setup.go

示例3: UploadImage

func UploadImage(w http.ResponseWriter, upload models.ImageUpload, req *http.Request, r render.Render, dbh *db.Dbh) {
	ur := &models.UploadResult{}

	rEmail := upload.Email
	rAlbum := upload.Album
	rPrivateKey := upload.PrivateKey

	fiName := upload.File.Filename

	upload_time := time.Now().Unix()

	ur.SetCode(200)
	ur.SetResult("success")
	ur.SetName(fiName)

	tmp_file := utils.ImageCfg.Root() + ur.GetName()

	if Exists(tmp_file) {
		log.Println("Error: File exists. (" + tmp_file + ")")
		ur.SetCode(2)
		ur.SetResult("File exists")
		r.JSON(500, ur)
		return
	}

	out, err := os.Create(tmp_file)
	if err != nil {
		log.Println("Error: Unable to open file.")
		ur.SetCode(500)
		ur.SetResult("Failed to open the file for writing.")
		r.JSON(500, ur)
		return
	}
	defer out.Close()

	fi, err := upload.File.Open()
	if err != nil {
		log.Println("fi err: ", err)
		ur.SetCode(500)
		ur.SetResult(err.Error())
		r.JSON(500, ur)
		return
	}
	defer fi.Close()

	_, err = io.Copy(out, fi)
	if err != nil {
		log.Println("Error: Failed to copy file.")
		ur.SetCode(500)
		ur.SetResult("Failed to copy file to new location.")
		r.JSON(500, ur)
		return
	}

	log.Printf("tmp_file: %s\n", tmp_file)

	// Add image uploader to database
	dbh.AddUploader(models.Uploader{Email: rEmail, Timestamp: upload_time})

	// Setup hashid to create unique file name
	var hid models.HashID
	hid.Init(utils.AppCfg.SecretKey(), 10)

	// Get user id
	user := dbh.GetUserByEmail(rEmail)
	log.Println("user: ", user.Id)
	if user.Id > 0 {
		// Add user id to hashid - seg 1
		hid.AddId(int(user.Id))
	} else {
		hid.AddId(0)
	}

	// Get uploader id
	user2 := dbh.GetUploaderByEmail(rEmail)
	log.Println("uploader user: ", user2.Id)
	if user2.Id > 0 {
		// Add uploader id to hashid - seg 2
		hid.AddId(int(user2.Id))
	} else {
		hid.AddId(0)
	}

	// Create default album description
	album := models.Album{
		Name:       rAlbum,
		User:       user.Id,
		Privatekey: rPrivateKey,
		Private:    true,
		Timestamp:  upload_time}
	album.DefaultDescription()
	log.Println(album)

	// Add album
	dbh.AddAlbum(album)

	log.Println("album: ", album)

	nAlbum := dbh.GetAlbum(rAlbum)

//.........這裏部分代碼省略.........
開發者ID:szwork2013,項目名稱:gopixelrelay,代碼行數:101,代碼來源:upload.go


注:本文中的pixelrelay/db.Dbh.GetUserByEmail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。