コード例 #1
0
def register():
	form = registerForm()
	if g.user: 
		return redirect(url_for("profile"))
	if form.validate_on_submit():
		user = User(
			email = form.email.data,
			firstName = form.firstName.data,
			lastName = form.lastName.data,
			# password = form.password.data,
			birthday = datetime.strptime(form.birthday_month.data + '%02d'%form.birthday_day.data + form.birthday_year.data, "%b%d%Y").date(),
			username = form.username.data
		)
		#logging.warning(str(user))
		user.put()
		sendConfirmEmail(user)

		session["username"] = user.username

		if not os.environ['SERVER_SOFTWARE'].startswith('Development'):	#if production, cuz mail doesn't work on dev.
			flash("A confirmation link has been sent to your email address.")
			return redirect(url_for("home"))
		else:
			token = URLSafeTimedSerializer(app.config['SECRET_KEY']).dumps(user.key.urlsafe(), salt=app.config['SECURITY_PASSWORD_SALT'])
			confirm_url = url_for("confirmEmail", token = token, _external = True)
			return "<a href={0}>Confirm</a>".format(confirm_url)	#let developer do it manually

	return render_template("register.html", form = form)
コード例 #2
0
def register():
    form = registerForm()
    if g.user:
        return redirect(url_for("profile"))
    if form.validate_on_submit():
        user = User(
            email=form.email.data,
            firstName=form.firstName.data,
            lastName=form.lastName.data,
            # password = form.password.data,
            birthday=datetime.strptime(
                form.birthday_month.data + '%02d' % form.birthday_day.data +
                form.birthday_year.data, "%b%d%Y").date(),
            username=form.username.data)
        #logging.warning(str(user))
        user.put()
        sendConfirmEmail(user)

        session["username"] = user.username

        if not os.environ['SERVER_SOFTWARE'].startswith(
                'Development'):  #if production, cuz mail doesn't work on dev.
            flash("A confirmation link has been sent to your email address.")
            return redirect(url_for("home"))
        else:
            token = URLSafeTimedSerializer(app.config['SECRET_KEY']).dumps(
                user.key.urlsafe(), salt=app.config['SECURITY_PASSWORD_SALT'])
            confirm_url = url_for("confirmEmail", token=token, _external=True)
            return "<a href={0}>Confirm</a>".format(
                confirm_url)  #let developer do it manually

    return render_template("register.html", form=form)
コード例 #3
0
 def create(user: User) -> ObjectId:
     try:
         user.password = sha256_crypt.encrypt(user.password)
         user_id = Base.users.insert_one(user.get_dict()).inserted_id
         return user_id
     except Exception as e:
         print(e)
         return None
コード例 #4
0
 def check(email: str, password: str) -> bool:
     user = Base.users.find_one({"email": email})
     if user:
         db_password = User.get_model(user).password
         if sha256_crypt.verify(password, db_password):
             return True
     return False
コード例 #5
0
    def on_post(self,req,resp):
        """
        Handle POST requests.
        """
        username = req.media.get('username')
        password = req.media.get('password')

        # Check if parameters not empty
        if None in (username, password):
            raise falcon.HTTPBadRequest('Bad Request', 'Invalid Parameters')

        # Hash user password
        hashed = pbkdf2_sha256.encrypt(password, rounds=200000, salt_size=16)

        # Now create main user for account
        user = User(username=username, password=hashed)

        self.db_conn.add(user)

        # Attempt database changes commit
        try:
            # Create User
            self.db_conn.commit()

        except SQLAlchemyError as e:

            # Rollback Changes
            self.db_conn.rollback()

            # Send error
            logger.error(f'Database Error: (Code: {e.orig.args[0]} Message: {e.orig.args[1]})')
            raise falcon.HTTPInternalServerError('Internal Server Error', 'An error ocurred while communicating with the database.')

        resp.media = {'success': 'user_created'}
        resp.status = falcon.HTTP_201
コード例 #6
0
def register():
    """ Register """
    name = request.json.get('name')
    email = request.json.get('email')
    password = request.json.get('password')

    if name is None or password is None or email is None:
        return parse_json("missing arguments", False)
    if UserService.does_exist(email):
        return parse_json("existing user", False)

    user = User(name, email, password, [])
    user_id = UserService.create(user)
    token = UserService.generate_auth_token(str(user_id))

    return parse_json({'token': token}, True)
コード例 #7
0
    def setUp(self):
        os.environ['APPLICATION_ID'] = 'touch-login'
        datastore_file = '/dev/null'
        from google.appengine.api import apiproxy_stub_map, datastore_file_stub
        apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
        stub = datastore_file_stub.DatastoreFileStub('touch-login',
                                                     datastore_file)
        apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)

        #If you think I know what that ^ does, you're wrong, I've got no idea.
        User(
            email="*****@*****.**",
            firstName="Vanya",
            lastName="Vegner",
            # password = form.password.data,
            username="******").put()

        flask_app.config['TESTING'] = True
        self.app = flask_app.test_client()
コード例 #8
0
    def get(email: str, user_id: ObjectId = None):
        user = Base.users.find_one(
            {"_id": user_id} if user_id else {"email": email})

        return User.get_model(user), user['_id']
コード例 #9
0
def lookupByUsername(username):
    user = User.query(User.username == username).get()
    if user is not None:
        return user
    else:
        return None
コード例 #10
0
def _lookupByUID(UID):
	user = User.query(User.UID == UID).get()
	if user is not None:
		return user
	else:
		return None
コード例 #11
0
ファイル: services.py プロジェクト: shmatt05/hackidc
 def __init__(self):
     self.data_service = get_data_service()
     self.default_user = User(
         name="Ari Propper",
         email="*****@*****.**",
         address="16, Rue Yafo, 94142 JERUSALEM, ISRAEL")
コード例 #12
0
def lookupByUsername(username):
	user = User.query(User.username == username).get()
	if user is not None:
		return user
	else:
		return None