예제 #1
0
func (c App) MaillistPost(usermaillist *models.UserMaillist, list string) revel.Result {
	usermaillist.Validate(c.Validation)

	if c.Validation.HasErrors() || (list != "weekly" && list != "longer") {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Maillist())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, usermaillist.Email)
	checkERROR(err)
	if UB != nil {
		c.Validation.Error("Email already taken").Key("usermaillist.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	err = c.addNewMaillistUser(usermaillist.Email, list)
	checkERROR(err)

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = usermaillist.Email + " is now subscribed to the " + list + " mailing list."

	return c.Redirect(routes.App.Result())

}
예제 #2
0
파일: app.go 프로젝트: kcolls/revel-modz
func (c App) LoginPost(email, password string) revel.Result {
	var found, valid bool

	c.Validation.Required(email).Message("Email required")
	c.Validation.Required(password).Message("Password required")

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Login())
	}

	// check for user in basic table
	UB := user.GetUserBasicByName(c.Txn, email)
	if UB != nil {
		found = true
	} else {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Login())
	}

	// check for user in auth table
	P := user.UserPass{UB.UserId, email, password}
	U, err := auth.Authenticate(c.Txn, &P)
	if err != nil || U == nil {
		revel.WARN.Println(err)
	} else {
		valid = true
	}

	if found && valid {
		c.Flash.Out["heading"] = "LOGIN PASS"
		c.Flash.Out["message"] = "Login successful for " + email

		c.Session["user"] = UB.UserName
		c.RenderArgs["user_basic"] = UB

		return c.Redirect(routes.User.Result())

	} else {
		c.Flash.Out["heading"] = "LOGIN FAIL"
		c.Flash.Out["message"] = "Login failed for " + email

		c.Validation.Keep()
		c.FlashParams()
		c.Redirect(routes.App.Login())
	}
	return c.Redirect(routes.App.Result())
}
예제 #3
0
파일: app.go 프로젝트: kcolls/revel-modz
func (c App) connected() *user.UserBasic {
	if c.RenderArgs["user_basic"] != nil {
		return c.RenderArgs["user_basic"].(*user.UserBasic)
	}
	if username, ok := c.Session["user"]; ok {
		u := user.GetUserBasicByName(c.Txn, username)
		if u == nil {
			revel.ERROR.Println("user field in Session[] not found in DB")
			return nil
		}
		// revel.WARN.Printf("connected :: %+v", *u)
		return u
	}
	return nil
}
예제 #4
0
func (c App) LoginPost(userlogin *models.UserLogin) revel.Result {
	userlogin.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Login())
	}

	var found, valid bool

	// check for user in basic table
	UB, err := user.GetUserBasicByName(c.Txn, userlogin.Email)
	checkERROR(err)
	if UB != nil {
		found = true
	} else {
		c.Flash.Error("unknown user")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Login())
	}

	// check for user in auth table
	passed, err := auth.Authenticate(c.Txn, UB.UserId, userlogin.Password)
	checkERROR(err)
	if !passed {
		c.Flash.Error("bad password")
	} else {
		valid = true
	}

	if found && valid {
		c.Session["user"] = UB.UserName
		c.RenderArgs["user_basic"] = UB

		// update visitor info in DB with UserId
		c.updateVisitorWithUserIdPanic()

		delete(c.Session, "v")
		delete(c.RenderArgs, "visitor")
		return c.Redirect(routes.User.Result())

	} else {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Login())
	}
}
예제 #5
0
func (c App) RegisterPost(userregister *models.UserRegister) revel.Result {
	userregister.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Register())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, userregister.Email)
	checkERROR(err)

	if UB != nil {
		c.Validation.Error("Email already taken").Key("userregister.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	checkERROR(err)

	// add user to tables
	// TODO do something more with the errors
	err = user.AddUserBasic(TestDB, uuid, userregister.Email)
	checkERROR(err)

	err = auth.AddUser(TestDB, UB.UserId, userregister.Password)
	checkERROR(err)

	// TODO  which mailing lists did they check off?
	err = maillist.AddUser(TestDB, uuid, userregister.Email, "weekly")
	checkERROR(err)

	// TODO add address / phone DB insert
	// ...

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = "you should be receiving an email at " +
		userregister.Email + " to confirm and activate your account."

	return c.Redirect(routes.App.Result())
}
예제 #6
0
파일: db.go 프로젝트: kcolls/revel-modz
func testDevDB() {
	for _, up := range dev_users {
		u := user.GetUserBasicByUserId(TestDB, up.UserId)
		if u == nil {
			revel.ERROR.Println("Failed to look up user by id:", up.UserId)
		}
		u = user.GetUserBasicByName(TestDB, up.UserName)
		if u == nil {
			revel.ERROR.Println("Failed to look up user by name:", up.UserName)
		}

		a, err := auth.Authenticate(TestDB, up)
		checkERROR(err)
		if a == nil {
			revel.ERROR.Printf("Failed to authenticate user: %+v\n", *up)
		}
	}
}
예제 #7
0
func (c App) SignupPost(usersignup *models.UserSignup) revel.Result {
	usersignup.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, usersignup.Email)
	checkERROR(err)

	if UB != nil {
		c.Validation.Error("Email already taken").Key("usersignup.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	checkERROR(err)

	// update visitor info in DB with UserId
	c.updateVisitorWithUserIdPanic()

	// add user to tables
	// TODO do something more with the errors
	err = user.AddUserBasic(TestDB, uuid, usersignup.Email)
	checkERROR(err)

	err = auth.AddUser(TestDB, UB.UserId, usersignup.Password)
	checkERROR(err)

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = "you should be receiving an email at " +
		usersignup.Email + " to confirm and activate your account."

	return c.Redirect(routes.App.Result())

}
예제 #8
0
func (c App) userConnected() *user.UserBasic {
	if c.RenderArgs["user_basic"] != nil {
		return c.RenderArgs["user_basic"].(*user.UserBasic)
	}
	if username, ok := c.Session["user"]; ok {
		u, err := user.GetUserBasicByName(c.Txn, username)
		checkERROR(err)
		if u == nil {
			revel.ERROR.Println("user field in Session[] not found in DB")
			return nil
		}

		// check ip addresses or something maybe

		// remove visitor fields in RenderArgs and Session?

		return u
	}
	return nil
}
예제 #9
0
파일: db.go 프로젝트: jwmiller19/revel-modz
func testUserDB() {
	for _, up := range dev_users {

		u, err := user.GetUserBasicById(TestDB, up.UserId)
		checkERROR(err)
		if u == nil {
			revel.ERROR.Println("Failed to look up user by id:", up.UserId)
		}

		u, err = user.GetUserBasicByName(TestDB, up.UserName)
		checkERROR(err)
		if u == nil {
			revel.ERROR.Println("Failed to look up user by name:", up.UserName)
		}

		passed, err := auth.Authenticate(TestDB, up.UserId, up.Password)
		checkERROR(err)
		if !passed {
			revel.ERROR.Printf("Failed to authenticate user: %+v\n", *up)
		}
	}
}
예제 #10
0
파일: app.go 프로젝트: kcolls/revel-modz
func (c App) addNewUser(email, password string) (*user.UserBasic, error) {
	// check for user in basic table
	UB := user.GetUserBasicByName(c.Txn, email)
	if UB != nil {
		c.Flash.Out["message"] = "Email: " + email + " already used"
		c.Validation.Keep()
		c.FlashParams()
		return nil, errors.New("UserBasic already in use")
	}

	// uuid := get random number (that isn't used already)
	uuid := int64(1001)
	UB = &user.UserBasic{
		UserId:   uuid,
		UserName: email,
	}

	// check for user in auth table
	UP := &user.UserPass{UB.UserId, email, password}
	UA, err := auth.Authenticate(c.Txn, UP)
	if UA != nil {
		c.Flash.Out["message"] = "Authentication Error"
		c.Validation.Keep()
		c.FlashParams()
		return nil, errors.New("UserAuth already in use")
	}

	// add user to tables

	err = user.AddUserBasic(TestDB, UB)
	checkERROR(err)

	_, err = auth.AddUserAuth(TestDB, UP)
	checkERROR(err)

	return UB, nil
}
예제 #11
0
파일: app.go 프로젝트: slnaing07/revel-modz
func (c App) userConnected() *user.UserBasic {
	if c.RenderArgs["user_basic"] != nil {
		return c.RenderArgs["user_basic"].(*user.UserBasic)
	}
	if username, ok := c.Session["user"]; ok {
		u, err := user.GetUserBasicByName(c.Txn, username)
		checkERROR(err)
		if u == nil {
			revel.ERROR.Println("user field in Session[] not found in DB")
			return nil
		}

		// update user info in DB, what info?

		if c.RenderArgs["visitor"] != nil {
			// update visitor info in DB with UserId
			c.updateVisitorWithUserIdPanic()
			// remove visitor fields in RenderArgs and Session?
		}

		return u
	}
	return nil
}
예제 #12
0
func (c App) RegisterPost(userregister *models.UserRegister) revel.Result {
	userregister.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Register())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, userregister.Email)
	checkERROR(err)

	if UB != nil {
		c.Validation.Error("Email already taken").Key("userregister.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	checkERROR(err)

	// update visitor info in DB with UserId
	c.updateVisitorWithUserIdPanic()

	// add user to tables
	// TODO do something more with the errors
	err = user.AddUserBasic(TestDB, uuid, userregister.Email)
	checkERROR(err)

	err = auth.AddUser(TestDB, UB.UserId, userregister.Password)
	checkERROR(err)

	// TODO  which mailing lists did they check off?
	err = maillist.AddUser(TestDB, uuid, userregister.Email, "weekly")
	checkERROR(err)

	// TODO add address / phone DB insert
	// ...
	addy := &user.UserAddress{
		UserId:       uuid,
		AddressType:  "default",
		AddressLine1: userregister.Address1,
		AddressLine2: userregister.Address2,
		City:         userregister.City,
		State:        userregister.State,
		Zip:          userregister.Zipcode,
		Country:      userregister.Country,
	}
	err = user.AddUserAddress(TestDB, addy)
	checkERROR(err)

	err = user.AddUserPhone(TestDB, uuid, "default", userregister.PhoneNumber)
	checkERROR(err)

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = "you should be receiving an email at " +
		userregister.Email + " to confirm and activate your account."

	return c.Redirect(routes.App.Result())
}