{"action":"created","issue":{"url":"https://api.github.com/repos/mattupstate/flask-security/issues/561","repository_url":"https://api.github.com/repos/mattupstate/flask-security","labels_url":"https://api.github.com/repos/mattupstate/flask-security/issues/561/labels{/name}","comments_url":"https://api.github.com/repos/mattupstate/flask-security/issues/561/comments","events_url":"https://api.github.com/repos/mattupstate/flask-security/issues/561/events","html_url":"https://github.com/mattupstate/flask-security/issues/561","id":188171325,"number":561,"title":"Redirect Issue in @login_required decorator in flask_security","user":{"login":"kartikdanidhariya","id":9051467,"avatar_url":"https://avatars.githubusercontent.com/u/9051467?v=3","gravatar_id":"","url":"https://api.github.com/users/kartikdanidhariya","html_url":"https://github.com/kartikdanidhariya","followers_url":"https://api.github.com/users/kartikdanidhariya/followers","following_url":"https://api.github.com/users/kartikdanidhariya/following{/other_user}","gists_url":"https://api.github.com/users/kartikdanidhariya/gists{/gist_id}","starred_url":"https://api.github.com/users/kartikdanidhariya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kartikdanidhariya/subscriptions","organizations_url":"https://api.github.com/users/kartikdanidhariya/orgs","repos_url":"https://api.github.com/users/kartikdanidhariya/repos","events_url":"https://api.github.com/users/kartikdanidhariya/events{/privacy}","received_events_url":"https://api.github.com/users/kartikdanidhariya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-09T05:47:34Z","updated_at":"2016-11-10T07:03:17Z","closed_at":null,"body":"hi i am using flask_security in my flask project \r\ni make successfully login using login_user(user) method \r\ni check it return true \r\nbut after that it redirect to login page again\r\nhow can i solve this issue"},"comment":{"url":"https://api.github.com/repos/mattupstate/flask-security/issues/comments/259616572","html_url":"https://github.com/mattupstate/flask-security/issues/561#issuecomment-259616572","issue_url":"https://api.github.com/repos/mattupstate/flask-security/issues/561","id":259616572,"user":{"login":"kartikdanidhariya","id":9051467,"avatar_url":"https://avatars.githubusercontent.com/u/9051467?v=3","gravatar_id":"","url":"https://api.github.com/users/kartikdanidhariya","html_url":"https://github.com/kartikdanidhariya","followers_url":"https://api.github.com/users/kartikdanidhariya/followers","following_url":"https://api.github.com/users/kartikdanidhariya/following{/other_user}","gists_url":"https://api.github.com/users/kartikdanidhariya/gists{/gist_id}","starred_url":"https://api.github.com/users/kartikdanidhariya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kartikdanidhariya/subscriptions","organizations_url":"https://api.github.com/users/kartikdanidhariya/orgs","repos_url":"https://api.github.com/users/kartikdanidhariya/repos","events_url":"https://api.github.com/users/kartikdanidhariya/events{/privacy}","received_events_url":"https://api.github.com/users/kartikdanidhariya/received_events","type":"User","site_admin":false},"created_at":"2016-11-10T07:03:17Z","updated_at":"2016-11-10T07:03:17Z","body":"hi my code is\r\n\r\n\r\nfrom flask import Flask, render_template,request,url_for\r\nfrom flask.ext.sqlalchemy import SQLAlchemy\r\nfrom flask.ext.security import Security, SQLAlchemyUserDatastore, \\\r\n    UserMixin, RoleMixin, login_required,login_user\r\nfrom flask_mail import Mail, Message\r\nfrom itsdangerous import (TimedJSONWebSignatureSerializer as Serializer, BadSignature, SignatureExpired)\r\nfrom itsdangerous import URLSafeTimedSerializer\r\nimport datetime\r\nfrom flask_security.utils import send_mail, md5, url_for_security, get_token_status, config_value, do_flash, get_message, send_mail, encrypt_password\r\nfrom flask_security.signals import user_registered\r\nfrom werkzeug.local import LocalProxy\r\n_security = LocalProxy(lambda: app.extensions['security'])\r\n\r\n_datastore = LocalProxy(lambda: _security.datastore)\r\n\r\n\r\n\r\n\r\n# Create app\r\napp = Flask(__name__)\r\napp.config['DEBUG'] = True\r\napp.config['SECRET_KEY'] = 'super-secret'\r\napp.config['SECURITY_PASSWORD_SALT'] = \"my_precious_two\"\r\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///user.db'\r\napp.config['SECURITY_RECOVERABLE'] = True\r\napp.config['SECURITY_REGISTERABLE'] = True\r\napp.config['SECURITY_CONFIRMABLE'] = True\r\napp.config[\"SECURITY_LOGIN_WITHOUT_CONFIRMATION\"] = True\r\n#app.config[\"SECURITY_CONFIRM_URL\"] = \"/confirm_new\"\r\n\r\napp.config['WTF_CSRF_ENABLED'] = True\r\napp.config['DEBUG_TB_ENABLED'] = False\r\napp.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False\r\n\r\napp.config['MAIL_SERVER']='mail.server.net'\r\napp.config['MAIL_PORT'] = 465\r\napp.config['MAIL_USERNAME'] = 'xxxxxxxxxxxxxxxxxxxx'\r\napp.config['MAIL_PASSWORD'] = 'xxxxxxxxxxxxxxxxxxxx'\r\napp.config['MAIL_USE_TLS'] = False\r\napp.config['MAIL_USE_SSL'] = True\r\napp.config['SEND_REGISTER_EMAIL'] = True\r\napp.config['EMAIL_SUBJECT_REGISTER'] = 'aaaaaaaaaaaaaaaaa'\r\n#app.config['SECURITY_SEND_REGISTER_EMAIL'] = True\r\nmail = Mail(app)\r\n# Create database connection object\r\ndb = SQLAlchemy(app)\r\n\r\n# Define models\r\nroles_users = db.Table('roles_users',\r\n        db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),\r\n        db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))\r\n\r\nclass Role(db.Model, RoleMixin):\r\n    id = db.Column(db.Integer(), primary_key=True)\r\n    name = db.Column(db.String(80), unique=True)\r\n    description = db.Column(db.String(255))\r\n\r\nclass User(db.Model, UserMixin):\r\n    id = db.Column(db.Integer, primary_key=True)\r\n    email = db.Column(db.String(255), unique=True)\r\n    password = db.Column(db.String(255))\r\n    active = db.Column(db.Boolean())\r\n    confirmed_at = db.Column(db.DateTime())\r\n    roles = db.relationship('Role', secondary=roles_users,\r\n                            backref=db.backref('users', lazy='dynamic'))\r\n   \r\n\r\n\r\n# Setup Flask-Security\r\nuser_datastore = SQLAlchemyUserDatastore(db, User, Role)\r\nsecurity = Security(app, user_datastore)\r\n\r\n\r\n\r\n@app.route(\"/RegisterUser\" , methods = ['POST','GET']) \r\ndef add_user():\r\n    if request.method == \"POST\":   \r\n        email = request.form['email']   \r\n        pwd = request.form['pwd']\r\n        #user_datastore.create_role(name='Admin')    \r\n        user_datastore.create_user(email=email,password=pwd,active=False,roles=['Admin']) \r\n        db.session.commit()\r\n     \tconfirmation_link, token = None, None\r\n        user = User.query.filter_by(email=email).first()\r\n        print \"user\",user\r\n\r\n        confirmation_link, token = generate_confirmation_link(user)\r\n        do_flash(*get_message('CONFIRM_REGISTRATION', email=email))\r\n\r\n\r\n        send_mail(config_value('EMAIL_SUBJECT_REGISTER'), email, 'welcome',\r\n                  user='kartik', confirmation_link=confirmation_link)\r\n        user_login =login_user(user,remember=True)\r\n        print \"user_login\",user_login\r\n\r\n    return \"User Registration Successfully...\"\r\n@app.route('/')\r\n@login_required\r\ndef home():\r\n    #return render_template('index.html')\r\n    return \"Login\"\r\n\r\n\r\n\r\n\r\n\r\n@app.route('/Login',methods=['GET','POST'])    \r\ndef LoginUser():    \r\n    if request.method == \"POST\":\r\n        print \"----------------------------\"\r\n        print request.form   \r\n        if User.query.filter_by(email=request.form['email']).first():\r\n            usr = User.query.filter_by(email=request.form['email']).first()\r\n            login_user(usr,remember=True)\r\n            return \"User Login Successfully...\"  \r\n    return \"Not Login\"      \r\n\r\n\r\ndef generate_confirmation_token(user):\r\n    \"\"\"Generates a unique confirmation token for the specified user.\r\n\r\n    :param user: The user to work with\r\n    \"\"\"\r\n    data = [str(user.id), md5(user.email)]\r\n    return _security.confirm_serializer.dumps(data)\r\n\r\ndef generate_confirmation_link(user):\r\n    token = generate_confirmation_token(user)\r\n    return url_for_security('confirm_email', token=token, _external=True), token\r\n\r\ndef confirm_user(user):\r\n    \"\"\"Confirms the specified user\r\n\r\n    :param user: The user to confirm\r\n    \"\"\"\r\n\t\r\n    if user.confirmed_at is not None:\r\n        return False\r\n    user.confirmed_at = datetime.utcnow()\r\n    user.active = True\r\n    _datastore.put(user)\r\n    user_confirmed.send(app._get_current_object(), user=user)\r\n    return True\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n    app.run()"}}
{"actor":{"display_login":"kartikdanidhariya"}}