示例#1
0
def create_users(session):
    # email,password,first_name,last_name,role
    users = [
        User("*****@*****.**", "changeit", "System2", "Administrator",
             "Admin"),
        User("*****@*****.**", "changeit", "Josh2", "Wase", "Guest")
    ]
    session.add_all(users)
    session.commit()
示例#2
0
def signup():
    name = utils.request.form_get('name')
    email = utils.request.form_get('email')
    password = utils.request.form_get('password')

    EMAIL_REGEX = r'(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])'

    if not re.fullmatch(EMAIL_REGEX, email):
        return jsonify(error='Invalid email.'), 400

    if len(password) < 7:
        return jsonify(
            error='Password must be at least 7 characters long.'), 400

    user = User.query.filter_by(email=email).first()

    if user:
        return jsonify(
            error='There is already an account registered with this email.'
        ), 409

    salt = bcrypt.gensalt()
    pwd_hash = bcrypt.hashpw(password.encode(), salt).decode()

    user = User(email, pwd_hash, name)
    db.session.add(user)
    db.session.commit()

    utils.mail.send_validate_email(
        email, utils.jwt.generate_validate_email_token(user))

    return jsonify(message='Registration succeeded.'), 201
示例#3
0
def post_new_user(login_session):
    newUser = User(name=login_session['username'], email=login_session[
                   'email'], picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
示例#4
0
def user_new():
    form = NewUserForm()
    if form.validate_on_submit():
        password_hash = pbkdf2_sha256.encrypt(form.password.data,
                                              rounds=200000,
                                              salt_size=16)
        user = User(form.fullname.data, form.username.data, password_hash)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for(".user"))
    return render_layout("admin_user_new.html", form=form)
示例#5
0
文件: auth.py 项目: yybest123/sharing
 def post(self):
     username = self.get_argument('username')
     email = self.get_argument("email")
     password = self.get_argument("password")
     # print username, email, password
     user1 = self.db.find(User, User.username == username).one()
     user2 = self.db.find(User, User.email == email).one()
     # print user1e
     if not user1 and not user2:
         user = User()
         user.username = username
         user.email = email
         user.password = password
         self.db.add(user)
         self.db.commit()
         self.render(
             "login.html", login_msg="signup successfully,please login!")
     else:
         self.render(
             "signup.html", signup_msg="your username or email has existed,please print again")
示例#6
0
def adduser():
    """Add a new user to the system"""
    print("Adding new user:"******"Real name")
    admin_login = prompt("Username")
    admin_pass = prompt_pass("Password")
    if admin_real_name is not None and admin_login is not None and admin_pass is not None:
        admin_hashed_pw = pbkdf2_sha256.encrypt(admin_pass, rounds=200000, salt_size=16)
        u = User(admin_real_name, admin_login, admin_hashed_pw, ["user"])
        db.session.add(u)
        db.session.commit()
    else:
        print("The provided data was invalid.")
示例#7
0
 async def add_user(session: AsyncSession) -> None:
     session.add(User(discord_id=author_id))