Ejemplo n.º 1
0
def user_register(request):
    if request.method == "GET":
        return render(request, 'user/user_register.html')
    elif request.method == "POST":
        try:
            username = request.POST.get("username")
            password = request.POST.get("password")
            email = request.POST.get("email")
            icon = request.FILES.get("icon")

            print(username)
            print(password)
            print(email)
            print(icon)

            user = UserModel()
            user.username = username
            # 添加数据安全
            password = generate_password(password)
            print(password)
            user.password = password
            user.email = email
            user.icon = icon
            user.save()
            request.session["user_id"] = user.id

            return redirect(reverse("axf:mine"))
        except Exception as e:
            return redirect(reverse("axf:user_register"))
    else:
        raise Exception("不被支持的请求")
Ejemplo n.º 2
0
def register_user():
    if request.method == 'GET':
        return render_template('register.html')
    if request.method == 'POST':
        user = UserModel()
        user.username = request.form.get('username')
        user.email = request.form.get('email')
        user.password = request.form.get('password')
        # user.user_id = request.form.get('user_id')
        if len(user.username) == 0 or len(user.email) == 0 or len(
                user.password) == 0:
            context = '请填写完整'
            return render_template('register.html', context=context)
        else:
            user.password = generate_password_hash(user.password)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('user.login_user'))
Ejemplo n.º 3
0
    def post(self):
        #注册

        #获取客户端提交过来的东西
        parse = parser.parse_args()
        username = parse.get('username')
        password = parse.get('password')
        email = parse.get('email')

        user = UserModel()

        user.name = username
        user.passwd = generate_password_hash(password)
        user.email = email
        #注册时设置token的值(唯一标识一个用户)
        user.token = str(uuid.uuid4())

        try:
            db.session.add(user)
            db.session.commit()
            #临时存储5分钟,在5分钟之内激活有效(临时存储user.token,user.id)
            cache.set(user.token, user.id, timeout=300)

            #给指定的邮箱发送邮件
            msg = Message(subject='用户激活',
                          sender='*****@*****.**',
                          recipients=[email])
            #邮箱内容
            msg.html = render_template(
                'email_active.html',
                username=username,
                active_url='http://127.0.0.1:5000/urr/?u_token=%s' %
                user.token)
            #发送
            mail.send(msg)

        except Exception as e:
            return {'returnCode': '-1', 'msg': e}

        return {'returnCode': '0', 'msg': 'success', 'returnValue': user}
Ejemplo n.º 4
0
    def post(self):
        username = request.form.get("username")
        password = request.form.get("password")
        email = request.form.get("email")
        icon = request.form.get("icon")
        data = {"msg": "ok", "status": "422"}
        if not username or not password:
            data["msg"] = "參數不正確"
            return jsonify(data), 422

        user = UserModel()
        user.username = username
        user.password = generate_password(password)
        user.email = email
        user.icon = icon
        try:
            db.session.add(user)
            db.session.commit()
            data["status"] = "201"
        except Exception as e:
            data["status"] = "901"
            data["msg"] = str(e)
        return jsonify(data), 201