HospitalRun / hospitalrun-frontend

Frontend for HospitalRun
https://staging.hospitalrun.io
MIT License
6.82k stars 2.18k forks source link

Login issue #1535

Closed akash65 closed 5 years ago

akash65 commented 6 years ago

Expected behavior:

When I try to login with credentials hradmin and test as username and password to login

Actual behavior:

But login credentials not working and it shows invalid username or password and I'm using couchdb 2.2

Steps to reproduce:

Screenshots (if applicable):

OS and Browser: Chrome lastest and windows 10

MatthewDorner commented 6 years ago

sorry things are not working well. Can you try this script and give a screenshot of the output? This one works for me with the CouchDB 2.2 I got from here: https://github.com/apache/couchdb-docker, though I'm still figuring out the details.

#!/bin/sh

URL="localhost"
PORT="5984"

if [ -z "${1}" ] || [ -z "${2}" ]; then
    HOST="http://$URL:$PORT"
    SECUREHOST="http://couchadmin:test@$URL:$PORT"
    echo "Setting up CouchDB for single node use"
    curl -X POST $SECUREHOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_single_node","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984}'
else
    SECUREHOST="http://$1:$2@$URL:$PORT"
fi

echo "Creating _users db"
curl -X PUT $SECUREHOST/_users
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
curl -X PUT $SECUREHOST/config/_design/auth -d "{ \"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) {if(userCtx.roles.indexOf('_admin')!== -1) {return;} else {throw({forbidden: 'This DB is read-only'});}}\"}"
echo "Setting up HospitalRun main DB"
curl -X PUT $SECUREHOST/main
curl -X PUT $SECUREHOST/main/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["user"]}}'
echo "Configure CouchDB authentication"
curl -X PUT $SECUREHOST/main/_design/auth -d "{\"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) { if(userCtx.roles.indexOf('_admin')!== -1 || userCtx.roles.indexOf('admin')!== -1){ if (newDoc._id.indexOf('_design') === 0) { return; }}if (newDoc._id.indexOf('_') !== -1) {var idParts=newDoc._id.split('_');if (idParts.length >= 3) { var allowedTypes=['allergy','appointment','attachment','billingLineItem','customForm','diagnosis','imaging','incCategory','incidentNote','incident','invLocation','invPurchase','invRequest','inventory','invoice','lab','lineItemDetail','lookup','medication','operationReport','operativePlan','option','overridePrice','patientNote','patient','payment','photo','priceProfile','pricing','procCharge','procedure','report','sequence','userRole','visit','vital'];if (allowedTypes.indexOf(idParts[0]) !== -1) {if(newDoc._deleted || newDoc.data) {return;}}}}throw({forbidden: 'Invalid data'});}\"}"
curl -X PUT $SECUREHOST/_node/_local/_config/http/authentication_handlers -d '"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, proxy_authentification_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"'
curl -X PUT $SECUREHOST/_node/_local/_config/couch_httpd_oauth/use_users_db -d '"true"'
echo "Add hradmin user for use in HospitalRun"
curl -X PUT $SECUREHOST/_users/org.couchdb.user:hradmin -d '{"name": "hradmin", "password": "test", "roles": ["System Administrator","admin","user"], "type": "user", "userPrefix": "p1"}'

Even if this works and you can login you will probably have issues with Administration -> Users due to the problems described here https://github.com/HospitalRun/hospitalrun-frontend/issues/953. It's easier to use CouchDB 1.7.1 if you can.

akash65 commented 6 years ago

Hello,

screenshot 176 screenshot 177

MatthewDorner commented 6 years ago

Did you already set a CouchDB admin username and password? I think the script should work whether you did or not, but if you did set one, it must be username: 'couchadmin' password: 'test'

akash65 commented 6 years ago

Yeah i tried the command inside cloned folder "../script/initcouch2.sh couchadmin test" while running these command username or password is incorrect screenshot 178

LowBP commented 6 years ago

@akash65 You should add "node_count":"3" to

   curl -X POST $HOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_cluster","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984}'
aalmangour commented 5 years ago

sorry things are not working well. Can you try this script and give a screenshot of the output? This one works for me with the CouchDB 2.2 I got from here: https://github.com/apache/couchdb-docker, though I'm still figuring out the details.

#!/bin/sh

URL="localhost"
PORT="5984"

if [ -z "${1}" ] || [ -z "${2}" ]; then
    HOST="http://$URL:$PORT"
    SECUREHOST="http://couchadmin:test@$URL:$PORT"
    echo "Setting up CouchDB for single node use"
    curl -X POST $SECUREHOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_single_node","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984}'
else
    SECUREHOST="http://$1:$2@$URL:$PORT"
fi

echo "Creating _users db"
curl -X PUT $SECUREHOST/_users
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
curl -X PUT $SECUREHOST/config/_design/auth -d "{ \"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) {if(userCtx.roles.indexOf('_admin')!== -1) {return;} else {throw({forbidden: 'This DB is read-only'});}}\"}"
echo "Setting up HospitalRun main DB"
curl -X PUT $SECUREHOST/main
curl -X PUT $SECUREHOST/main/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["user"]}}'
echo "Configure CouchDB authentication"
curl -X PUT $SECUREHOST/main/_design/auth -d "{\"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) { if(userCtx.roles.indexOf('_admin')!== -1 || userCtx.roles.indexOf('admin')!== -1){ if (newDoc._id.indexOf('_design') === 0) { return; }}if (newDoc._id.indexOf('_') !== -1) {var idParts=newDoc._id.split('_');if (idParts.length >= 3) { var allowedTypes=['allergy','appointment','attachment','billingLineItem','customForm','diagnosis','imaging','incCategory','incidentNote','incident','invLocation','invPurchase','invRequest','inventory','invoice','lab','lineItemDetail','lookup','medication','operationReport','operativePlan','option','overridePrice','patientNote','patient','payment','photo','priceProfile','pricing','procCharge','procedure','report','sequence','userRole','visit','vital'];if (allowedTypes.indexOf(idParts[0]) !== -1) {if(newDoc._deleted || newDoc.data) {return;}}}}throw({forbidden: 'Invalid data'});}\"}"
curl -X PUT $SECUREHOST/_node/_local/_config/http/authentication_handlers -d '"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, proxy_authentification_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"'
curl -X PUT $SECUREHOST/_node/_local/_config/couch_httpd_oauth/use_users_db -d '"true"'
echo "Add hradmin user for use in HospitalRun"
curl -X PUT $SECUREHOST/_users/org.couchdb.user:hradmin -d '{"name": "hradmin", "password": "test", "roles": ["System Administrator","admin","user"], "type": "user", "userPrefix": "p1"}'

Even if this works and you can login you will probably have issues with Administration -> Users due to the problems described here #953. It's easier to use CouchDB 1.7.1 if you can.

I tried this script, still I cannot login

LowBP commented 5 years ago

@aalmangour please send me the output of your script? Result of your script screenshot 20

please try this script

#!/bin/sh

URL="localhost"
PORT="5984"

if [ -z "${1}" ] || [ -z "${2}" ]; then
    HOST="http://$URL:$PORT"
    SECUREHOST="http://couchadmin:test@$URL:$PORT"
    echo "Setting up CouchDB for single node use"
    curl -X POST $HOST/_cluster_setup -H 'Content-Type: application/json' -d '{"action":"enable_cluster","username":"couchadmin","password":"test","bind_address":"0.0.0.0","port":5984, "node_count":"3"}'
    else
    SECUREHOST="http://$1:$2@$URL:$PORT"
fi

echo "Creating _users db"
curl -X PUT $SECUREHOST/_users
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
curl -X PUT $SECUREHOST/config/_design/auth -d "{ \"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) {if(userCtx.roles.indexOf('_admin')!== -1) {return;} else {throw({forbidden: 'This DB is read-only'});}}\"}"
echo "Setting up HospitalRun main DB"
curl -X PUT $SECUREHOST/main
curl -X PUT $SECUREHOST/main/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["user"]}}'
echo "Configure CouchDB authentication"
curl -X PUT $SECUREHOST/main/_design/auth -d "{\"validate_doc_update\": \"function(newDoc, oldDoc, userCtx) { if(userCtx.roles.indexOf('_admin')!== -1 || userCtx.roles.indexOf('admin')!== -1){ if (newDoc._id.indexOf('_design') === 0) { return; }}if (newDoc._id.indexOf('_') !== -1) {var idParts=newDoc._id.split('_');if (idParts.length >= 3) { var allowedTypes=['allergy','appointment','attachment','billingLineItem','customForm','diagnosis','imaging','incCategory','incidentNote','incident','invLocation','invPurchase','invRequest','inventory','invoice','lab','lineItemDetail','lookup','medication','operationReport','operativePlan','option','overridePrice','patientNote','patient','payment','photo','priceProfile','pricing','procCharge','procedure','report','sequence','userRole','visit','vital'];if (allowedTypes.indexOf(idParts[0]) !== -1) {if(newDoc._deleted || newDoc.data) {return;}}}}throw({forbidden: 'Invalid data'});}\"}"
curl -X PUT $SECUREHOST/_node/_local/_config/http/authentication_handlers -d '"{couch_httpd_oauth, oauth_authentication_handler}, {couch_httpd_auth, proxy_authentification_handler}, {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"'
curl -X PUT $SECUREHOST/_node/_local/_config/couch_httpd_oauth/use_users_db -d '"true"'
echo "Add hradmin user for use in HospitalRun"
curl -X PUT $SECUREHOST/_users/org.couchdb.user:hradmin -d '{"name": "hradmin", "password": "test", "roles": ["System Administrator","admin","user"], "type": "user", "userPrefix": "p1"}'

The expected result

screenshot 21

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.