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


Golang db.GetCollection函数代码示例

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


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

示例1: NewManager

//NewManager creates and initializes a new Manager
func NewManager(r *http.Request) *Manager {
	session := db.GetDBSession(r)
	return &Manager{
		session:    session,
		collection: db.GetCollection(session, mongoCollectionName),
	}
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:8,代码来源:db.go

示例2: GetByKeyEmailAddressValidationInformation

func (manager *Manager) GetByKeyEmailAddressValidationInformation(key string) (info *EmailAddressValidationInformation, err error) {
	mgoCollection := db.GetCollection(manager.session, mongoOngoingEmailAddressValidationCollectionName)
	err = mgoCollection.Find(bson.M{"key": key}).One(&info)
	if err == mgo.ErrNotFound {
		info = nil
		err = nil
	}
	return
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:9,代码来源:db.go

示例3: IsEmailAddressValidated

func (manager *Manager) IsEmailAddressValidated(username string, emailaddress string) (validated bool, err error) {
	mgoCollection := db.GetCollection(manager.session, mongoValidatedEmailAddresses)
	count, err := mgoCollection.Find(bson.M{"username": username, "emailaddress": emailaddress}).Count()
	validated = false
	if err != nil {
		return
	}
	if count != 0 {
		validated = true
	}
	return
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:12,代码来源:db.go

示例4: IsPhonenumberValidated

func (manager *Manager) IsPhonenumberValidated(username string, phonenumber string) (validated bool, err error) {
	mgoCollection := db.GetCollection(manager.session, mongoValidatedPhonenumbers)
	count, err := mgoCollection.Find(bson.M{"username": username, "phonenumber": phonenumber}).Count()
	validated = false
	if err != nil {
		return
	}
	if count != 0 {
		validated = true
	}
	return
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:12,代码来源:db.go

示例5: GetSmsCode

//GetSmsCode returns an sms code for a specified phone label
func (service *Service) GetSmsCode(w http.ResponseWriter, request *http.Request) {
	phoneLabel := mux.Vars(request)["phoneLabel"]
	loginSession, err := service.GetSession(request, SessionLogin, "loginsession")
	if err != nil {
		log.Error("Error getting login session", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	sessionInfo, err := newLoginSessionInformation()
	if err != nil {
		log.Error("Error creating login session information", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	username, ok := loginSession.Values["username"].(string)
	if username == "" || !ok {
		http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
		return
	}
	userMgr := user.NewManager(request)
	userFromDB, err := userMgr.GetByName(username)
	if err != nil {
		log.Error("Error getting user", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	phoneNumber, err := userFromDB.GetPhonenumberByLabel(phoneLabel)
	if err != nil {
		log.Debug(userFromDB.Phonenumbers)
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}
	loginSession.Values["sessionkey"] = sessionInfo.SessionKey
	authClientId := loginSession.Values["auth_client_id"]
	authenticatingOrganization := ""
	if authClientId != nil {
		authenticatingOrganization = authClientId.(string)
	}
	mgoCollection := db.GetCollection(db.GetDBSession(request), mongoLoginCollectionName)
	mgoCollection.Insert(sessionInfo)
	organizationText := ""
	if authenticatingOrganization != "" {
		split := strings.Split(authenticatingOrganization, ".")
		organizationText = fmt.Sprintf("to authorize the organization %s, ", split[len(split)-1])
	}
	smsmessage := fmt.Sprintf("To continue signing in at itsyou.online %senter the code %s in the form or use this link: https://%s/sc?c=%s&k=%s",
		organizationText, sessionInfo.SMSCode, request.Host, sessionInfo.SMSCode, url.QueryEscape(sessionInfo.SessionKey))
	sessions.Save(request, w)
	go service.smsService.Send(phoneNumber.Phonenumber, smsmessage)
	w.WriteHeader(http.StatusNoContent)
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:52,代码来源:login.go

示例6: getLoginSessionInformation

func (service *Service) getLoginSessionInformation(request *http.Request, sessionKey string) (sessionInfo *loginSessionInformation, err error) {

	if sessionKey == "" {
		sessionKey, err = service.getSessionKey(request)
		if err != nil || sessionKey == "" {
			return
		}
	}

	mgoCollection := db.GetCollection(db.GetDBSession(request), mongoLoginCollectionName)
	sessionInfo = &loginSessionInformation{}
	err = mgoCollection.Find(bson.M{"sessionkey": sessionKey}).One(sessionInfo)
	if err == mgo.ErrNotFound {
		sessionInfo = nil
		err = nil
	}
	return
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:18,代码来源:login.go

示例7: MobileSMSConfirmation

//MobileSMSConfirmation is the page that is linked to in the SMS and is thus accessed on the mobile phone
func (service *Service) MobileSMSConfirmation(w http.ResponseWriter, request *http.Request) {

	err := request.ParseForm()
	if err != nil {
		log.Debug("ERROR parsing mobile smsconfirmation form", err)
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	values := request.Form
	sessionKey := values.Get("k")
	smscode := values.Get("c")

	var validsmscode bool
	sessionInfo, err := service.getLoginSessionInformation(request, sessionKey)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	if sessionInfo == nil {
		service.renderSMSConfirmationPage(w, request, "Invalid or expired link")
		return
	}

	validsmscode = (smscode == sessionInfo.SMSCode)

	if !validsmscode { //TODO: limit to 3 failed attempts
		service.renderSMSConfirmationPage(w, request, "Invalid or expired link")
		return
	}
	mgoCollection := db.GetCollection(db.GetDBSession(request), mongoLoginCollectionName)

	_, err = mgoCollection.UpdateAll(bson.M{"sessionkey": sessionKey}, bson.M{"$set": bson.M{"confirmed": true}})
	if err != nil {
		log.Error("Error while confirming sms 2fa - ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	service.renderSMSConfirmationPage(w, request, "You will be logged in within a few seconds")
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:42,代码来源:login.go

示例8: GetByPhoneNumber

func (manager *Manager) GetByPhoneNumber(searchString string) (validatedPhonenumber ValidatedPhonenumber, err error) {
	mgoCollection := db.GetCollection(manager.session, mongoValidatedPhonenumbers)
	err = mgoCollection.Find(bson.M{"phonenumber": searchString}).One(&validatedPhonenumber)
	return validatedPhonenumber, err
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:5,代码来源:db.go

示例9: HasValidatedPhones

func (manager *Manager) HasValidatedPhones(username string) (hasValidatedPhones bool, err error) {
	count, err := db.GetCollection(manager.session, mongoValidatedPhonenumbers).Find(bson.M{"username": username}).Count()
	hasValidatedPhones = count > 0
	return hasValidatedPhones, err
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:5,代码来源:db.go

示例10: getCollection

func getCollection(session *mgo.Session) *mgo.Collection {
	return db.GetCollection(session, mongoCollectionName)
}
开发者ID:yveskerwyn,项目名称:identityserver,代码行数:3,代码来源:db.go

示例11: getAccessTokenCollection

//getAccessTokenCollection returns the mongo collection for the accessTokens
func (m *Manager) getAccessTokenCollection() *mgo.Collection {
	return db.GetCollection(m.session, tokensCollectionName)
}
开发者ID:yveskerwyn,项目名称:identityserver,代码行数:4,代码来源:db.go

示例12: getUserCollection

func (m *Manager) getUserCollection() *mgo.Collection {
	return db.GetCollection(m.session, mongoUsersCollectionName)
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:3,代码来源:db.go

示例13: getClientsCollection

//getClientsCollection returns the mongo collection for the clients
func (m *Manager) getClientsCollection() *mgo.Collection {
	return db.GetCollection(m.session, clientsCollectionName)
}
开发者ID:yveskerwyn,项目名称:identityserver,代码行数:4,代码来源:db.go

示例14: GetByEmailAddress

func (manager *Manager) GetByEmailAddress(searchString string) (validatedEmailaddress ValidatedEmailAddress, err error) {
	mgoCollection := db.GetCollection(manager.session, mongoValidatedEmailAddresses)
	err = mgoCollection.Find(bson.M{"emailaddress": searchString}).One(&validatedEmailaddress)
	return validatedEmailaddress, err
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:5,代码来源:db.go

示例15: SavePhonenumberValidationInformation

//SavePhonenumberValidationInformation stores a validated phonenumber.
func (manager *Manager) SavePhonenumberValidationInformation(info *PhonenumberValidationInformation) (err error) {
	mgoCollection := db.GetCollection(manager.session, mongoOngoingPhonenumberValidationCollectionName)
	_, err = mgoCollection.Upsert(bson.M{"phonenumber": info.Phonenumber}, info)
	return
}
开发者ID:itsyouonline,项目名称:identityserver,代码行数:6,代码来源:db.go


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