Beispiel #1
0
 def check_user_existence(self, email, phone):
     query = {"$or": [{"email": email}, {"phone": phone}]}
     user_check = User.objects(__raw__=query).first()
     if user_check:
         return True, "User exists in the system"
     else:
         return False, "User not exists"
Beispiel #2
0
 def verify_loggedin_user(self, username, password):
     query = {"$or": [{"email": username}, {"phone": username}]}
     user_check = User.objects(__raw__=query).first()
     if user_check:
         if self.pwd_context.verify(password, user_check.password):
             return True, "User Exists in the System"
         return False, "Invalid Password"
     return False, "User not exists"
Beispiel #3
0
 def post(self):
     data = api.payload
     user = User(user_id=data['user_id'],
                 email=data['email'],
                 first_name=data['first_name'],
                 last_name=data['last_name'])
     user.set_password(data['password'])
     # user.save()
     return jsonify(User.objects(user_id=data['user_id']))
Beispiel #4
0
def login():
    if session.get('username'):
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        user = User.objects(email=email).first()
        if user and user.get_password(password):
            flash(f"{user.first_name} You are logged in successfully!!!",
                  "success")
            session['user_id'] = user.user_id
            session['username'] = user.first_name
            return redirect(url_for('index'))
        else:
            flash("Something went wrong!", "danger")
    return render_template("login.html", form=form, title="Log In", login=True)
Beispiel #5
0
 def delete(self, idx):
     User.objects(user_id=idx).delete()
     return jsonify("User is deleted")
Beispiel #6
0
 def put(self, idx):
     data = api.payload
     User.objects(user_id=idx).update(**data)
     return jsonify(User.objects(user_id=idx))
Beispiel #7
0
 def get(self, idx):
     return jsonify(User.objects(user_id=idx))
Beispiel #8
0
 def validate_email(self, email):
     user = User.objects(email=email.data).first()
     if user:
         raise ValidationError("Email already in use.Try another.")