auth.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:varapp-backend-py 作者: varapp 项目源码 文件源码
def create_user(username, password, firstname, lastname, email, phone, email_to_file=None):
    if not validate_username(username):
        return [None, "Wrong user name format (are allowed a-Z|0-9|.|-|_)"]
    if not validate_email(email):
        return [None, "Wrong email format"]
    if Users.objects.filter(username=username):
        logging.warning("Cannot create account: username {} already exists".format(email))
        return [None, "This username already exists"]
    if Users.objects.filter(email=email):
        logging.warning("Cannot create account: email {} already exists".format(email))
        return [None, "This email already exists"]
    person = People.objects.create(firstname=firstname, lastname=lastname, phone=phone, is_laboratory=0)
    role = Roles.objects.get(name=DEFAULT_ROLE)
    salt = crypt.mksalt(method=crypt.METHOD_SHA256)
    newuser = Users(username=username, password=crypt.crypt(password, salt),
                    salt=salt, email=email, person=person, role=role,
                    is_active=0, is_password_reset=0, code=utils.random_string())
    newuser.save()
    allow_access_to_demo(newuser)
    text = "Your account '{}' has been created. ".format(username) + \
        "It will be validated by an admin shortly. You will receive an email at this " + \
        "address when your account has been activated."
    html = text
    send_email(email, "New varapp account", text=text, html=html, tofile=email_to_file)
    send_email(settings.EMAIL_ADMIN, "Account for user {} awaits validation".format(username),
                     text='', html='', tofile=email_to_file)
    return [newuser, '']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号