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


Golang User.Authenticate方法代碼示例

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


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

示例1: setUserAttribute

func setUserAttribute(user content.User, secret []byte, attr string, data []byte) (resp responseError) {
	resp = newResponse()
	in := user.Data()
	resp.val["Login"] = in.Login

	switch attr {
	case "FirstName":
		resp.err = json.Unmarshal(data, &in.FirstName)
	case "LastName":
		resp.err = json.Unmarshal(data, &in.LastName)
	case "Email":
		resp.err = json.Unmarshal(data, &in.Email)
	case "ProfileData":
		if resp.err = json.Unmarshal(data, &in.ProfileData); resp.err == nil {
			in.ProfileJSON = []byte{}
		}
	case "Active":
		in.Active = string(data) == "true"
	case "Password":
		passwd := struct {
			Current string
			New     string
		}{}
		if resp.err = json.Unmarshal(data, &passwd); resp.err != nil {
			/* TODO: non-fatal error */
			return
		}
		if user.Authenticate(passwd.Current, secret) {
			user.Password(passwd.New, secret)
			resp.err = user.Err()
		} else {
			resp.err = errors.New("Error change user password: current password is invalid")
		}
	default:
		resp.err = errors.New("Error getting user attribute: unknown attribute " + attr)
	}

	if resp.err != nil {
		return
	}

	user.Data(in)
	user.Update()
	if resp.err = user.Err(); resp.err != nil {
		return
	}

	resp.val["Success"] = true
	resp.val["Attribute"] = attr

	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:52,代碼來源:user-settings.go

示例2: Handler

func (controller TtRss) Handler(c context.Context) http.Handler {
	repo := readeef.GetRepo(c)
	logger := webfw.GetLogger(c)
	config := readeef.GetConfig(c)

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		action := webfw.GetMultiPatternIdentifier(c, r)

		if action == "redirecter" {
			http.Redirect(w, r, "/", http.StatusMovedPermanently)
		}

		req := ttRssRequest{}

		resp := ttRssResponse{}

		var err error
		var errType string
		var user content.User
		var con interface{}

		switch {
		default:
			var b []byte
			in := map[string]interface{}{}

			if b, err = ioutil.ReadAll(r.Body); err != nil {
				err = fmt.Errorf("reading request body: %s", err)
				break
			}

			if err = json.Unmarshal(b, &in); err != nil {
				err = fmt.Errorf("decoding JSON request: %s", err)
				break
			}

			req = ttRssConvertRequest(in)

			logger.Debugf("Request: %#v\n", req)

			resp.Seq = req.Seq

			if req.Op != "login" && req.Op != "isLoggedIn" {
				if sess, ok := ttRssSessions[req.Sid]; ok {
					user = repo.UserByLogin(data.Login(sess.login))
					if repo.Err() != nil {
						errType = "NOT_LOGGED_IN"
					} else {
						sess.lastVisit = time.Now()
						ttRssSessions[req.Sid] = sess
					}
				} else {
					errType = "NOT_LOGGED_IN"
				}
			}

			if errType != "" {
				logger.Debugf("TT-RSS Sessions: %#v\n", ttRssSessions)
				break
			}

			logger.Debugf("TT-RSS OP: %s\n", req.Op)
			switch req.Op {
			case "getApiLevel":
				con = ttRssGenericContent{Level: TTRSS_API_LEVEL}
			case "getVersion":
				con = ttRssGenericContent{Version: TTRSS_VERSION}
			case "login":
				user = repo.UserByLogin(data.Login(req.User))
				if repo.Err() != nil {
					errType = "LOGIN_ERROR"
					err = fmt.Errorf("getting TT-RSS user: %s", repo.Err())
					break
				}

				if !user.Authenticate(req.Password, []byte(config.Auth.Secret)) {
					errType = "LOGIN_ERROR"
					err = fmt.Errorf("authentication for TT-RSS user '%s'", user.Data().Login)
					break
				}

				var sessId string

				login := user.Data().Login

				for id, sess := range ttRssSessions {
					if sess.login == login {
						sessId = id
					}
				}

				if sessId == "" {
					sessId = strings.Replace(util.UUID(), "-", "", -1)
					ttRssSessions[sessId] = ttRssSession{login: login, lastVisit: time.Now()}
				}

				con = ttRssGenericContent{
					ApiLevel:  TTRSS_API_LEVEL,
					SessionId: sessId,
				}
//.........這裏部分代碼省略.........
開發者ID:urandom,項目名稱:readeef,代碼行數:101,代碼來源:tt_rss.go


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