move database login to model
fix bug