prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Unable to login to the Admin Panel.
  **Description:**
  When we try to login to admin panel, even if the credentials belong to super-admin, it returns "Credential incorrect"
  
  **Steps to reproduce the behavior:**
  1. Go to 127.0.0.1:5000/admin
  2. Enter the admin credentials
  3. Click on login button
  4. See error "Credential incorrect"
  
  **Expected Behaviour:**
  It should login the user to the admin panel if credentials are correct and the user is an admin.
  
  **Screenshots**
  ![error](https://user-images.githubusercontent.com/32808710/52912510-5d3b4180-32d8-11e9-93e6-86843c8f6fb4.png)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/views/__init__.py`
  Content:
  ```
  1 import flask_login as login
  2 import requests
  3 from flask import url_for, redirect, Blueprint, request, make_response
  4 from flask_admin import Admin, AdminIndexView, expose, helpers as admin_helpers
  5 from flask_admin.contrib.sqla import ModelView
  6 from flask_scrypt import generate_password_hash
  7 from wtforms import form, fields, validators
  8 
  9 from app.models import db
  10 from app.models.user import User
  11 
  12 
  13 class AdminModelView(ModelView):
  14     def is_accessible(self):
  15         return login.current_user.is_authenticated
  16 
  17     def inaccessible_callback(self, name, **kwargs):
  18         # redirect to login page if user doesn't have access
  19         return redirect(url_for('admin.index', next=request.url))
  20 
  21 
  22 class LoginForm(form.Form):
  23     login = fields.TextField(validators=[validators.required(), validators.email()], render_kw={"placeholder": "john.doe@example.com"})
  24     password = fields.PasswordField(validators=[validators.required()], render_kw={"placeholder": "xyzzy"})
  25 
  26     def validate_login(self, field):
  27         """
  28         validate login
  29         :param field:
  30         :return:
  31         """
  32         user = self.get_user()
  33 
  34         if user is None:
  35             raise validators.ValidationError('User does not exist.')
  36 
  37         if user.password != generate_password_hash(self.password.data, user.salt):
  38             raise validators.ValidationError('Credentials incorrect.')
  39 
  40         if not user.is_admin and not user.is_super_admin:
  41             raise validators.ValidationError('Access Forbidden. Admin Rights Required')
  42 
  43     def get_user(self):
  44         return User.query.filter_by(email=self.login.data).first()
  45 
  46 
  47 class MyAdminIndexView(AdminIndexView):
  48     @expose('/')
  49     def index(self):
  50         """
  51         /admin
  52         :return:
  53         """
  54         if not login.current_user.is_authenticated:
  55             return redirect(url_for('.login_view'))
  56         return super(MyAdminIndexView, self).index()
  57 
  58     @expose('/login/', methods=('GET', 'POST'))
  59     def login_view(self):
  60         """
  61         login view for flask-admin
  62         :return:
  63         """
  64         # handle user login
  65         form = LoginForm(request.form)
  66         if admin_helpers.validate_form_on_submit(form):
  67             user = form.get_user()
  68             login.login_user(user)
  69 
  70         if login.current_user.is_authenticated:
  71             return redirect(url_for('.index'))
  72         self._template_args['form'] = form
  73         return super(MyAdminIndexView, self).index()
  74 
  75     @expose('/logout/')
  76     def logout_view(self):
  77         login.logout_user()
  78         return redirect(url_for('.index'))
  79 
  80 
  81 home_routes = Blueprint('home', __name__)
  82 
  83 
  84 # Flask views
  85 @home_routes.route('/')
  86 def index():
  87     """
  88     Index route
  89     :return:
  90     """
  91     r = requests.get('https://raw.githubusercontent.com/fossasia/open-event-server/gh-pages/api/v1/index.html')
  92     response = make_response(r.content)
  93     response.headers["Content-Type"] = "text/html"
  94     return response
  95 
  96 
  97 class BlueprintsManager:
  98     def __init__(self):
  99         pass
  100 
  101     @staticmethod
  102     def register(app):
  103         """
  104         Register blueprints
  105         :param app: a flask app instance
  106         :return:
  107         """
  108         app.register_blueprint(home_routes)
  109         admin = Admin(app, name='Open Event API', template_mode='bootstrap3', index_view=MyAdminIndexView(),
  110                       base_template='admin_base.html')
  111 
  112         # Get all the models in the db, all models should have a explicit __tablename__
  113         classes, models, table_names = [], [], []
  114         # noinspection PyProtectedMember
  115         for class_ in list(db.Model._decl_class_registry.values()):
  116             try:
  117                 table_names.append(class_.__tablename__)
  118                 classes.append(class_)
  119             except:
  120                 pass
  121         for table in list(db.metadata.tables.items()):
  122             if table[0] in table_names:
  123                 models.append(classes[table_names.index(table[0])])
  124 
  125         for model in models:
  126             admin.add_view(AdminModelView(model, db.session))
  127
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/app/views/__init__.py b/app/views/__init__.py
  --- a/app/views/__init__.py
  +++ b/app/views/__init__.py
  @@ -3,7 +3,6 @@
   from flask import url_for, redirect, Blueprint, request, make_response
   from flask_admin import Admin, AdminIndexView, expose, helpers as admin_helpers
   from flask_admin.contrib.sqla import ModelView
  -from flask_scrypt import generate_password_hash
   from wtforms import form, fields, validators
   
   from app.models import db
  @@ -34,7 +33,7 @@
           if user is None:
               raise validators.ValidationError('User does not exist.')
   
  -        if user.password != generate_password_hash(self.password.data, user.salt):
  +        if not user.is_correct_password(self.password.data):
               raise validators.ValidationError('Credentials incorrect.')
   
           if not user.is_admin and not user.is_super_admin:
  
verification_info: {"golden_diff": "diff --git a/app/views/__init__.py b/app/views/__init__.py\n--- a/app/views/__init__.py\n+++ b/app/views/__init__.py\n@@ -3,7 +3,6 @@\n from flask import url_for, redirect, Blueprint, request, make_response\n from flask_admin import Admin, AdminIndexView, expose, helpers as admin_helpers\n from flask_admin.contrib.sqla import ModelView\n-from flask_scrypt import generate_password_hash\n from wtforms import form, fields, validators\n \n from app.models import db\n@@ -34,7 +33,7 @@\n         if user is None:\n             raise validators.ValidationError('User does not exist.')\n \n-        if user.password != generate_password_hash(self.password.data, user.salt):\n+        if not user.is_correct_password(self.password.data):\n             raise validators.ValidationError('Credentials incorrect.')\n \n         if not user.is_admin and not user.is_super_admin:\n", "issue": "Unable to login to the Admin Panel.\n**Description:**\r\nWhen we try to login to admin panel, even if the credentials belong to super-admin, it returns \"Credential incorrect\"\r\n\r\n**Steps to reproduce the behavior:**\r\n1. Go to 127.0.0.1:5000/admin\r\n2. Enter the admin credentials\r\n3. Click on login button\r\n4. See error \"Credential incorrect\"\r\n\r\n**Expected Behaviour:**\r\nIt should login the user to the admin panel if credentials are correct and the user is an admin.\r\n\r\n**Screenshots**\r\n![error](https://user-images.githubusercontent.com/32808710/52912510-5d3b4180-32d8-11e9-93e6-86843c8f6fb4.png)\r\n\n", "before_files": [{"content": "import flask_login as login\nimport requests\nfrom flask import url_for, redirect, Blueprint, request, make_response\nfrom flask_admin import Admin, AdminIndexView, expose, helpers as admin_helpers\nfrom flask_admin.contrib.sqla import ModelView\nfrom flask_scrypt import generate_password_hash\nfrom wtforms import form, fields, validators\n\nfrom app.models import db\nfrom app.models.user import User\n\n\nclass AdminModelView(ModelView):\n    def is_accessible(self):\n        return login.current_user.is_authenticated\n\n    def inaccessible_callback(self, name, **kwargs):\n        # redirect to login page if user doesn't have access\n        return redirect(url_for('admin.index', next=request.url))\n\n\nclass LoginForm(form.Form):\n    login = fields.TextField(validators=[validators.required(), validators.email()], render_kw={\"placeholder\": \"john.doe@example.com\"})\n    password = fields.PasswordField(validators=[validators.required()], render_kw={\"placeholder\": \"xyzzy\"})\n\n    def validate_login(self, field):\n        \"\"\"\n        validate login\n        :param field:\n        :return:\n        \"\"\"\n        user = self.get_user()\n\n        if user is None:\n            raise validators.ValidationError('User does not exist.')\n\n        if user.password != generate_password_hash(self.password.data, user.salt):\n            raise validators.ValidationError('Credentials incorrect.')\n\n        if not user.is_admin and not user.is_super_admin:\n            raise validators.ValidationError('Access Forbidden. Admin Rights Required')\n\n    def get_user(self):\n        return User.query.filter_by(email=self.login.data).first()\n\n\nclass MyAdminIndexView(AdminIndexView):\n    @expose('/')\n    def index(self):\n        \"\"\"\n        /admin\n        :return:\n        \"\"\"\n        if not login.current_user.is_authenticated:\n            return redirect(url_for('.login_view'))\n        return super(MyAdminIndexView, self).index()\n\n    @expose('/login/', methods=('GET', 'POST'))\n    def login_view(self):\n        \"\"\"\n        login view for flask-admin\n        :return:\n        \"\"\"\n        # handle user login\n        form = LoginForm(request.form)\n        if admin_helpers.validate_form_on_submit(form):\n            user = form.get_user()\n            login.login_user(user)\n\n        if login.current_user.is_authenticated:\n            return redirect(url_for('.index'))\n        self._template_args['form'] = form\n        return super(MyAdminIndexView, self).index()\n\n    @expose('/logout/')\n    def logout_view(self):\n        login.logout_user()\n        return redirect(url_for('.index'))\n\n\nhome_routes = Blueprint('home', __name__)\n\n\n# Flask views\n@home_routes.route('/')\ndef index():\n    \"\"\"\n    Index route\n    :return:\n    \"\"\"\n    r = requests.get('https://raw.githubusercontent.com/fossasia/open-event-server/gh-pages/api/v1/index.html')\n    response = make_response(r.content)\n    response.headers[\"Content-Type\"] = \"text/html\"\n    return response\n\n\nclass BlueprintsManager:\n    def __init__(self):\n        pass\n\n    @staticmethod\n    def register(app):\n        \"\"\"\n        Register blueprints\n        :param app: a flask app instance\n        :return:\n        \"\"\"\n        app.register_blueprint(home_routes)\n        admin = Admin(app, name='Open Event API', template_mode='bootstrap3', index_view=MyAdminIndexView(),\n                      base_template='admin_base.html')\n\n        # Get all the models in the db, all models should have a explicit __tablename__\n        classes, models, table_names = [], [], []\n        # noinspection PyProtectedMember\n        for class_ in list(db.Model._decl_class_registry.values()):\n            try:\n                table_names.append(class_.__tablename__)\n                classes.append(class_)\n            except:\n                pass\n        for table in list(db.metadata.tables.items()):\n            if table[0] in table_names:\n                models.append(classes[table_names.index(table[0])])\n\n        for model in models:\n            admin.add_view(AdminModelView(model, db.session))\n", "path": "app/views/__init__.py"}], "after_files": [{"content": "import flask_login as login\nimport requests\nfrom flask import url_for, redirect, Blueprint, request, make_response\nfrom flask_admin import Admin, AdminIndexView, expose, helpers as admin_helpers\nfrom flask_admin.contrib.sqla import ModelView\nfrom wtforms import form, fields, validators\n\nfrom app.models import db\nfrom app.models.user import User\n\n\nclass AdminModelView(ModelView):\n    def is_accessible(self):\n        return login.current_user.is_authenticated\n\n    def inaccessible_callback(self, name, **kwargs):\n        # redirect to login page if user doesn't have access\n        return redirect(url_for('admin.index', next=request.url))\n\n\nclass LoginForm(form.Form):\n    login = fields.TextField(validators=[validators.required(), validators.email()], render_kw={\"placeholder\": \"john.doe@example.com\"})\n    password = fields.PasswordField(validators=[validators.required()], render_kw={\"placeholder\": \"xyzzy\"})\n\n    def validate_login(self, field):\n        \"\"\"\n        validate login\n        :param field:\n        :return:\n        \"\"\"\n        user = self.get_user()\n\n        if user is None:\n            raise validators.ValidationError('User does not exist.')\n\n        if not user.is_correct_password(self.password.data):\n            raise validators.ValidationError('Credentials incorrect.')\n\n        if not user.is_admin and not user.is_super_admin:\n            raise validators.ValidationError('Access Forbidden. Admin Rights Required')\n\n    def get_user(self):\n        return User.query.filter_by(email=self.login.data).first()\n\n\nclass MyAdminIndexView(AdminIndexView):\n    @expose('/')\n    def index(self):\n        \"\"\"\n        /admin\n        :return:\n        \"\"\"\n        if not login.current_user.is_authenticated:\n            return redirect(url_for('.login_view'))\n        return super(MyAdminIndexView, self).index()\n\n    @expose('/login/', methods=('GET', 'POST'))\n    def login_view(self):\n        \"\"\"\n        login view for flask-admin\n        :return:\n        \"\"\"\n        # handle user login\n        form = LoginForm(request.form)\n        if admin_helpers.validate_form_on_submit(form):\n            user = form.get_user()\n            login.login_user(user)\n\n        if login.current_user.is_authenticated:\n            return redirect(url_for('.index'))\n        self._template_args['form'] = form\n        return super(MyAdminIndexView, self).index()\n\n    @expose('/logout/')\n    def logout_view(self):\n        login.logout_user()\n        return redirect(url_for('.index'))\n\n\nhome_routes = Blueprint('home', __name__)\n\n\n# Flask views\n@home_routes.route('/')\ndef index():\n    \"\"\"\n    Index route\n    :return:\n    \"\"\"\n    r = requests.get('https://raw.githubusercontent.com/fossasia/open-event-server/gh-pages/api/v1/index.html')\n    response = make_response(r.content)\n    response.headers[\"Content-Type\"] = \"text/html\"\n    return response\n\n\nclass BlueprintsManager:\n    def __init__(self):\n        pass\n\n    @staticmethod\n    def register(app):\n        \"\"\"\n        Register blueprints\n        :param app: a flask app instance\n        :return:\n        \"\"\"\n        app.register_blueprint(home_routes)\n        admin = Admin(app, name='Open Event API', template_mode='bootstrap3', index_view=MyAdminIndexView(),\n                      base_template='admin_base.html')\n\n        # Get all the models in the db, all models should have a explicit __tablename__\n        classes, models, table_names = [], [], []\n        # noinspection PyProtectedMember\n        for class_ in list(db.Model._decl_class_registry.values()):\n            try:\n                table_names.append(class_.__tablename__)\n                classes.append(class_)\n            except:\n                pass\n        for table in list(db.metadata.tables.items()):\n            if table[0] in table_names:\n                models.append(classes[table_names.index(table[0])])\n\n        for model in models:\n            admin.add_view(AdminModelView(model, db.session))\n", "path": "app/views/__init__.py"}]}