summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2017-05-18 22:30:58 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2017-05-24 03:07:01 (GMT)
commit4950be46ed6883868ef4a05bccf52978c1110c46 (patch)
treecb2280a98d89101ccb008c4bf87ed094a30e6ccd
parent0f49d9c5a8f418564786c463df297ec7c8932ee2 (diff)
downloadvaranusex-4950be46ed6883868ef4a05bccf52978c1110c46.zip
varanusex-4950be46ed6883868ef4a05bccf52978c1110c46.tar.gz
varanusex-4950be46ed6883868ef4a05bccf52978c1110c46.tar.bz2
account/new-user: implement db part
-rw-r--r--requirements.txt1
-rw-r--r--varanusex/models/users.py15
-rw-r--r--varanusex/templates/account/register-new-user.html16
-rw-r--r--varanusex/utilities.py7
-rw-r--r--varanusex/views/account.py26
-rw-r--r--varanusex/views/account_web_forms.py9
6 files changed, 64 insertions, 10 deletions
diff --git a/requirements.txt b/requirements.txt
index faaa067..7123621 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,3 +4,4 @@ flask_sqlalchemy
flask_login
wtforms
passlib
+captcha
diff --git a/varanusex/models/users.py b/varanusex/models/users.py
index 86126d9..a1718a8 100644
--- a/varanusex/models/users.py
+++ b/varanusex/models/users.py
@@ -27,8 +27,9 @@ import re
import hashlib
import pprint
import base64
+import datetime
from .. import db
-from ..utilities import parse_ssh_pubkey
+from ..utilities import parse_ssh_pubkey, epoch_now
class User(UserMixin,db.Model):
__tablename__ = 'user'
@@ -38,16 +39,20 @@ class User(UserMixin,db.Model):
email = db.Column(db.Text, nullable=False)
user_pw = db.Column(db.String(128), nullable=False, default='')
realname = db.Column(db.String(32), nullable=False, default='')
- status = db.Column(db.String(16), nullable=False, index=True, default='A')
- uidNumber = db.Column(db.Integer, index=True)
+ status = db.Column(db.String(16), nullable=False, index=True, default='P')
+
+ # Hack Alert: Savannah currently fills the uidNumber field
+ # using an external cronjob, see 'sv_assign_uid_gid' script
+ # in https://savannah.gnu.org/maintenance/UserAuthentication/
+ uidNumber = db.Column(db.Integer, index=True,nullable=True)
spamscore = db.Column(db.Integer, default='0')
- add_date = db.Column(db.Integer, nullable=False, default='0')
+ add_date = db.Column(db.Integer, nullable=False, default=epoch_now)
confirm_hash = db.Column(db.String(32))
authorized_keys = db.Column(db.Text)
authorized_keys_count = db.Column(db.Integer)
email_new = db.Column(db.Text)
people_view_skills = db.Column(db.Integer, nullable=False, default='0')
- people_resume = db.Column(db.Text, nullable=False)
+ people_resume = db.Column(db.Text, nullable=False, default='')
timezone = db.Column(db.String(64), default='GMT')
theme = db.Column(db.String(15), default='')
email_hide = db.Column(db.String(3), default='0')
diff --git a/varanusex/templates/account/register-new-user.html b/varanusex/templates/account/register-new-user.html
index c1a2b42..bf3a4e4 100644
--- a/varanusex/templates/account/register-new-user.html
+++ b/varanusex/templates/account/register-new-user.html
@@ -44,6 +44,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
{% endfor %}
<br/>
+ {{ form.realname.label }}
+ {{ form.realname(size=20) }}
+ {% for message in form.realname.errors %}
+ <div class="formerror">{{ message }}</div>
+ {% endfor %}
+ <br/>
+
+ {{ form.email.label }}
+ {{ form.email(size=20) }}
+ {% for message in form.email.errors %}
+ <div class="formerror">{{ message }}</div>
+ {% endfor %}
+ <br/>
+
{{ form.password1.label }}
{{ form.password1(size=20) }}
{% for message in form.password1.errors %}
@@ -60,7 +74,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<br/>
<input class="pure-button pure-button-primary"
- type="submit" value="Change Password">
+ type="submit" value="register">
<a class="pure-button" href="{{ url_for('account_config') }}">Cancel</a>
diff --git a/varanusex/utilities.py b/varanusex/utilities.py
index 6df8c8b..8053645 100644
--- a/varanusex/utilities.py
+++ b/varanusex/utilities.py
@@ -23,6 +23,7 @@ import base64
from subprocess import Popen,PIPE
from tempfile import TemporaryFile
from pprint import pprint
+from datetime import datetime
def get_cgi_item_id(args):
"""
@@ -188,3 +189,9 @@ def valid_gpg_pubkey(key):
# Step 2: Feed it to GPG
return valid_gpg_packets(key)
+
+
+
+def epoch_now():
+ """Returns the unix timestamp"""
+ return datetime.utcnow().strftime("%s")
diff --git a/varanusex/views/account.py b/varanusex/views/account.py
index 9a06c41..a9cf504 100644
--- a/varanusex/views/account.py
+++ b/varanusex/views/account.py
@@ -70,16 +70,34 @@ def logout():
@app.route('/register',methods=['GET','POST'])
def account_register():
+ #a = "qQeErRtTiIaAdfFgGhHLbBnNM2346789"
+ #l = ''.join([ random.choice(a) for x in range(5) ])
+ #d = hashlib.sha256( l.encode('ascii') . str(randon.randint(1,50000)) )
+
f = RegisterNewUserForm()
if f.validate_on_submit():
u = f.username.data.strip()
- p = f.password1.data.strip()
+ e = f.email.data.strip()
user = User.query.filter_by(user_name=u).first()
- if not user:
- pass
+ user2 = User.query.filter_by(email=e).first()
+ if not user and not user2:
+ p = f.password1.data.strip()
+ r = f.realname.data.strip()
+
+ nu = User()
+ nu.user_name = u
+ nu.email = e
+ nu.set_new_password(p)
+ nu.realname = r
+
+ db.session.add(nu)
+ db.session.commit()
else:
- f.username.errors.append("user already exists")
+ if user:
+ f.username.errors.append("user is taken")
+ if user2:
+ f.email.errors.append("email already registered")
return render_template('account/register-new-user.html',form=f)
diff --git a/varanusex/views/account_web_forms.py b/varanusex/views/account_web_forms.py
index d44fa56..228d34f 100644
--- a/varanusex/views/account_web_forms.py
+++ b/varanusex/views/account_web_forms.py
@@ -43,6 +43,15 @@ class RegisterNewUserForm(Form):
InputRequired(message="Username is required.")
])
+ realname = StringField('Real name',
+ validators=[
+ InputRequired(message="Name is required.")
+ ])
+
+ email = StringField('Email',
+ validators=[InputRequired(message="Email is required."),
+ Email(message="Invalid email address.")])
+
password1 = PasswordField('password',
validators=[InputRequired(),
EqualTo('password2',