ExpertManager.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "ExpertManager.h"
  2. #include <dbService/ClassSet.h>
  3. #include <dbService/UserService.h>
  4. #include <QCryptographicHash>
  5. int ExpertManager::addUser(QFUser user)
  6. {
  7. if (user.userNo.isEmpty()) {
  8. return QF_CODE_EMPTY_ACCOUNT;
  9. }
  10. if (user.rawPassword().isEmpty()) {
  11. return QF_CODE_EMPTY_PASSWORD;
  12. }
  13. if (user.userName.isEmpty()) {
  14. return QF_CODE_EMPTY_USERNAME;
  15. }
  16. QCryptographicHash ch(QCryptographicHash::Md5);
  17. QString md5str;
  18. QByteArray md5bytes = QCryptographicHash::hash(user.password.toLatin1(), QCryptographicHash::Md5);
  19. md5str.prepend(md5bytes.toHex());
  20. user.password = md5str;
  21. if (-1 == UserService().AddUserInfo(user)) {
  22. return QF_CODE_ACCOUNT_OCCUPIED;
  23. }
  24. return QF_CODE_ADD_USER_SUCCEEDED;
  25. }
  26. int ExpertManager::deleteUser(int userId)
  27. {
  28. bool ret = UserService().DeleteUserById(userId);
  29. if (!ret) {
  30. return QF_CODE_DELETE_USER_FAILED;
  31. }
  32. // UserService().DeleteUserConfigByEngineerId(userId);
  33. return QF_CODE_DELETE_USER_SUCCEEDED;
  34. }