Skip to content
Snippets Groups Projects
Commit b22bb7fa authored by ale's avatar ale
Browse files

add invited_by field to the User model

parent 9f56b8f1
No related branches found
No related tags found
No related merge requests found
......@@ -27,8 +27,13 @@ class UserDetailsForm(Form):
raise ValidationError('Passwords are different')
def is_new_user(form, field):
if User.query.filter_by(email=str(field.data)).first():
raise ValidationError('This user has already been invited')
class InviteForm(Form):
email = TextField('Email to invite', [validators.Email()])
email = TextField('Email to invite', [validators.Email(), is_new_user])
class LoginForm(Form):
......@@ -104,7 +109,7 @@ def user_send_invite():
username = user.email.split('@')[0]
email = form.email.data
new_user = User(email, 'x')
new_user = User(email, 'x', invited_by=g.userid)
svcs['mailer'].send(email, 'Invitation',
new_user.get_activation_email(username))
......
......@@ -48,15 +48,17 @@ class User(Base):
email = Column(String(128), index=True, unique=True)
password = Column(String(128))
created_at = Column(DateTime())
invited_by = Column(Integer())
active = Column(Boolean())
activation_token = Column(String(40))
def __init__(self, email, password):
def __init__(self, email, password, invited_by=None):
self.email = email
self.set_password(password)
self.active = False
self.activation_token = utils.random_token()
self.created_at = datetime.now()
self.invited_by = invited_by
def set_password(self, password):
self.password = crypt.crypt(password, _salt())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment