Golang RequestBundle.VerifyEmail方法代码示例

本文整理汇总了Golang中get/2cloud/org/twocloud.RequestBundle.VerifyEmail方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestBundle.VerifyEmail方法的具体用法?Golang RequestBundle.VerifyEmail怎么用?Golang RequestBundle.VerifyEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在get/2cloud/org/twocloud.RequestBundle的用法示例。


Golang RequestBundle.VerifyEmail方法代码示例

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

示例1: verifyEmail

func verifyEmail(w http.ResponseWriter, r *twocloud.RequestBundle) {
	var req verifyEmailRequest
	user := r.AuthUser
	username := r.Request.URL.Query().Get(":username")
	if strings.ToLower(username) != strings.ToLower(r.AuthUser.Username) {
		if !r.AuthUser.IsAdmin {
			Respond(w, r, http.StatusForbidden, "You don't have access to that user's account.", []interface{}{})
			return
		}
		id, err := r.GetUserID(username)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusInternalServerError, "Internal server error.", []interface{}{})
			return
		}
		user, err = r.GetUser(id)
		if err != nil {
			r.Log.Error(err.Error())
			Respond(w, r, http.StatusInternalServerError, "Internal server error.", []interface{}{})
			return
		}
	}
	body, err := ioutil.ReadAll(r.Request.Body)
	if err != nil {
		r.Log.Error(err.Error())
		Respond(w, r, http.StatusInternalServerError, "Internal server error.", []interface{}{})
		return
	}
	err = json.Unmarshal(body, &req)
	if err != nil {
		r.Log.Error(err.Error())
		Respond(w, r, http.StatusBadRequest, "Error decoding request.", []interface{}{})
		return
	}
	if req.Code == "" {
		Respond(w, r, http.StatusBadRequest, "Code must be set.", []interface{}{})
		return
	}
	err = r.VerifyEmail(user, req.Code)
	if err == twocloud.InvalidConfirmationCodeError {
		Respond(w, r, http.StatusBadRequest, "Invalid confirmation code.", []interface{}{})
		return
	} else if err != nil {
		r.Log.Error(err.Error())
		Respond(w, r, http.StatusInternalServerError, "Internal server error.", []interface{}{})
		return
	}
	user.EmailUnconfirmed = false
	Respond(w, r, http.StatusOK, "Successfully verified email address", []interface{}{user})
	return
}
开发者ID:2cloud,项目名称:api,代码行数:51,代码来源:users.go

本文标签属性:

示例:示例志愿表

代码:代码转换器

Golang:golang面试题

RequestBundle:RequestBundle

VerifyEmail:verifyemailaddress应该填什么

上一篇:C++ NM_DEVICE_BT_GET_PRIVATE函数代码示例(c++get_private函数的15个代码示例)
下一篇:Java PersistenceContext.isDefaultReadOnly方法代码示例

为您推荐