Exemplo n.º 1
0
//@param streamId
//@param streamTitle
//@return publishId if err==nil and pubilshId==nil, not allow taken
//streamId can only be taken once a time
func CreateNewPublish(userId int, streamId, streamTitle string, streamQuality, streamOrientation int) (publishId string, err error) {
	timestamp := time.Now().Unix()
	orm.NewOrm().QueryTable("LiveVideo").Filter("StreamId", streamId).Filter("EndTime", 0).Update(orm.Params{
		"EndTime": timestamp,
	})

	publishId = utils.Md5Hash(fmt.Sprintf("%s:%s:%d", streamId, streamTitle, timestamp))
	user := User{Id: userId}
	newPublish := LiveVideo{
		User:        &user,
		PublishId:   publishId,
		Title:       streamTitle,
		StreamId:    streamId,
		Quality:     streamQuality,
		Orientation: streamOrientation,
		StartTime:   timestamp,
	}

	_, cErr := orm.NewOrm().Insert(&newPublish)
	if cErr != nil {
		err = cErr
		return
	}

	return
}
Exemplo n.º 2
0
//@param mobile
//@param pwd
//@output loginResult
//@return ok, not found, error
func UserLogin(mobile, pwd string, loginResult *LoginResult) {
	user, qErr := model.GetUserByMobile(mobile)
	if qErr != nil {
		if qErr == orm.ErrNoRows {
			loginResult.SetCode(API_USER_NOT_FOUND_ERROR)
		} else {
			loginResult.SetCode(API_SERVER_ERROR)
		}
		return
	}

	if user.Pwd != utils.Md5Hash(pwd) {
		loginResult.SetCode(API_USER_PWD_ERROR)
		return
	}

	sessionId := utils.CreateSessionId(user.Mobile, user.Pwd)
	cErr := model.SetSession(user.Id, sessionId)
	if cErr != nil {
		loginResult.SetCode(API_SERVER_ERROR)
		return
	}

	loginResult.UserName = user.Name
	loginResult.SessionId = sessionId
	loginResult.SetOk()

	return
}
Exemplo n.º 3
0
//create new user, if mobile exists, err it
func CreateNewUser(mobile, pwd, name, email string) (err error) {
	user := &User{
		Mobile: mobile,
		Name:   name,
		Pwd:    utils.Md5Hash(pwd),
		Email:  email,
	}
	_, err = orm.NewOrm().Insert(user)
	return
}