当前位置: 首页>>代码示例>>Golang>>正文


Golang models.User类代码示例

本文整理汇总了Golang中github.com/robmeades/utm/service/models.User的典型用法代码示例。如果您正苦于以下问题:Golang User类的具体用法?Golang User怎么用?Golang User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Profile

// TODO
func (u *User) Profile(response http.ResponseWriter, request *http.Request) {
	user_id, _ := utilities.GetUserId(request)
	db := utilities.GetDB(request)
	user := new(models.User)
	user.Get(db, user_id)
	user.Password = ""
	out, _ := json.Marshal(user)
	response.Write(out)
}
开发者ID:mmanjoura,项目名称:utm,代码行数:10,代码来源:user.go

示例2: UserUEs

/// Method for the authentication struct that takes
// an HTTP request and returns an HTTP response containing
// the friendly names of the devices against a user's e-mail.
func (a *Auth) UserUEs(request http.ResponseWriter, response *http.Request) {
	db := utilities.GetDB(response)
	session := sessions.GetSession(response)
	user_email := session.Get("user_email")
	fmt.Println(user_email)
	if user_email == nil {
		request.WriteHeader(403)
	} else {
		user := new(models.User)
		ues := user.GetUEs(db, user_email.(string))
		fmt.Println(ues)
		outData, _ := json.Marshal(ues)
		request.Write(outData)
	}
}
开发者ID:mmanjoura,项目名称:utm,代码行数:18,代码来源:auth.go

示例3: Uuids

/// Method for the authentication struct that takes
// an HTTP request and returns an HTTP response containing
// all the UUIDs for a user.
func (a *Auth) Uuids(request http.ResponseWriter, response *http.Request) {
	db := utilities.GetDB(response)
	session := sessions.GetSession(response)
	user_company := session.Get("user_company")
	fmt.Println(user_company)
	if user_company == nil {
		request.WriteHeader(403)
	} else {
		user := new(models.User)
		uuids := user.GetUserUuids(db, user_company.(string))
		fmt.Println(uuids)
		outData, _ := json.Marshal(uuids)
		request.Write(outData)
	}
}
开发者ID:mmanjoura,项目名称:utm,代码行数:18,代码来源:auth.go

示例4: registerHandler

func registerHandler(response http.ResponseWriter, request *http.Request) {

	company := request.FormValue("company_name")
	firstName := request.FormValue("user_firstName")
	lastName := request.FormValue("user_lastName")
	email := request.FormValue("email")
	password := request.FormValue("password")

	db := utilities.GetDB(request)
	user := new(models.User)

	user.NewUser(db, company, firstName, lastName, email, password)

	http.Redirect(response, request, "/display", 302)
}
开发者ID:mmanjoura,项目名称:mus-utm,代码行数:15,代码来源:handlers.go

示例5: Get

/// Method for the user struct that takes an HTTP request and
// returns an HTTP response containing the user's details for
// their ID.
func (u *User) Get(response http.ResponseWriter, request *http.Request) {
	vars := mux.Vars(request)
	id := vars["id"]

	db := utilities.GetDB(request)
	user := new(models.User)
	err := user.Get(db, id)
	if err != nil {
		response.WriteHeader(404)
	} else {
		user.Password = ""
		out, _ := json.Marshal(user)
		response.Write(out)
	}
}
开发者ID:mmanjoura,项目名称:utm,代码行数:18,代码来源:user.go

示例6: Login

/// Login method for the authentication struct that takes
// an HTTP request and returns an HTTP response.
// A session is created if successful.
func (a *Auth) Login(request http.ResponseWriter, response *http.Request) {
	fmt.Fprintf(request, "Welcome to the login page!")
	// decoder := json.NewDecoder(response.Body)
	// credentials := new(Credentials)
	// err := decoder.Decode(&credentials)
	// if err != nil {
	// 	panic(err)
	// }

	// db := utilities.GetDB(response)
	// user := new(models.User)
	// err = user.Authenticate(db, credentials.Email, credentials.Password)
	// if err == nil {
	// 	session := sessions.GetSession(response)
	// 	session.Set("user_id", user.ID.Hex())
	// 	session.Set("user_company", user.Company)
	// 	session.Set("user_email", user.Email)
	// 	request.WriteHeader(202)

	// } else {
	// 	request.WriteHeader(404)
	// }

	email := response.FormValue("email")
	password := response.FormValue("password")

	db := utilities.GetDB(response)
	user := new(models.User)
	err := user.Authenticate(db, email, password)
	if err == nil {
		//session := sessions.GetSession(request)
		// session.Set("user_id", user.ID.Hex())
		// session.Set("user_company", user.Company)
		// session.Set("user_email", user.Email)
		//response.WriteHeader(202)
		http.Redirect(request, response, "http://localhost:3000", 202)
		http.Redirect(request, response, "/", 202)
		fmt.Fprintf(request, "error is nil!")
		//http.Redirect(response, request, "/", 202)

	} else {
		//fmt.Fprintf(request, "There is Error!")
		//http.Redirect(request, response, "http://localhost:3000", 202)
		// http.Redirect(request, response, "http://localhost:3000/lastestState", 202)
		// request.WriteHeader(404)
	}
}
开发者ID:mmanjoura,项目名称:utm,代码行数:50,代码来源:auth.go

示例7: loginHandler

func loginHandler(response http.ResponseWriter, request *http.Request) {

	email := request.FormValue("email")
	password := request.FormValue("password")
	session := sessions.GetSession(request)

	db := utilities.GetDB(request)
	user := new(models.User)
	err := user.Authenticate(db, email, password)
	fmt.FPrintf("Calling login User session \n%s", spew.Sdump(user_id))
	if err == nil {
		session.Set("user_id", user.ID.Hex())
		session.Set("user_company", user.Company)
		session.Set("user_email", user.Email)
		http.Redirect(response, request, "/display", 302)
	} else {
		http.Redirect(response, request, "/", 302)

	}
}
开发者ID:mmanjoura,项目名称:mus-utm,代码行数:20,代码来源:handlers.go


注:本文中的github.com/robmeades/utm/service/models.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。