~ubuntu-branches/ubuntu/raring/voxbo/raring

« back to all changes in this revision

Viewing changes to client/addUser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-06-06 11:33:11 UTC
  • Revision ID: james.westby@ubuntu.com-20100606113311-v3c13imdkkd5n7ae
Tags: upstream-1.8.5~svn1172
ImportĀ upstreamĀ versionĀ 1.8.5~svn1172

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* A simple qt interface to add new users. */
 
2
 
 
3
using namespace std;
 
4
 
 
5
#include <QMessageBox>
 
6
#include <iostream>
 
7
#include "addUser.h"
 
8
#include "bdb_tab.h"
 
9
#include "dbclient.h"
 
10
 
 
11
// Global pointer to DBclient
 
12
extern DBclient* dbcp;
 
13
 
 
14
/* Simple constructor */
 
15
newUser::newUser(QWidget *parent) 
 
16
  : QDialog(parent) 
 
17
{
 
18
  mainUI.setupUi(this);
 
19
 
 
20
  // Customized signal-slot pairs
 
21
  connect(mainUI.okButton, SIGNAL(clicked()), this, SLOT(sendVal()));
 
22
  connect(mainUI.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 
23
}
 
24
 
 
25
/* Check information in the form and submit to user database.
 
26
 * Before sending the data on the form to user databse, make sure:
 
27
 * (1) Account name and passwd fields are not blank;
 
28
 * (2) Account name is unique;
 
29
 * (3) Passwd confirmation matches exactly the initial one. */
 
30
void newUser::sendVal()
 
31
{
 
32
  // Is account field blank?
 
33
  if (mainUI.account->text().isEmpty()) {
 
34
    QMessageBox::warning(0, "Error in add user form", "Account name is required.");
 
35
    return;
 
36
  }
 
37
 
 
38
  // Is password field blank?
 
39
  if (mainUI.passwd->text().isEmpty()) {
 
40
    QMessageBox::warning(0, "Error in add user form", "Password field is required.");
 
41
    mainUI.passwd->setFocus();
 
42
    return;
 
43
  }
 
44
 
 
45
  // Is password confirmation blank?
 
46
  if (mainUI.confirmation->text().isEmpty()) {
 
47
    QMessageBox::warning(0, "Error in add user form", "Password confirmation field is required.");
 
48
    mainUI.confirmation->setFocus();
 
49
    return;
 
50
  }
 
51
 
 
52
  // Is password and confirmation match with each other?
 
53
  if (mainUI.passwd->text() != mainUI.confirmation->text()) {
 
54
    QMessageBox::warning(0, "Error in add user form", "confirmed password doesn't match the initial one.");
 
55
    mainUI.confirmation->setFocus();
 
56
    mainUI.confirmation->selectAll();
 
57
    return;
 
58
  }
 
59
 
 
60
  userGUI uiData;
 
61
  string substring;
 
62
  substring = mainUI.account->text().toStdString();
 
63
  if (substring.length())
 
64
    uiData.setAccount(substring);
 
65
 
 
66
  substring = mainUI.name->text().toStdString();
 
67
  if (substring.length())
 
68
    uiData.setName(substring);
 
69
 
 
70
  substring = mainUI.phone->text().toStdString();
 
71
  if (substring.length())
 
72
    uiData.setPhone(substring);
 
73
 
 
74
  substring = mainUI.email->text().toStdString();
 
75
  if (substring.length())
 
76
    uiData.setEmail(substring);
 
77
 
 
78
  substring = mainUI.address->text().toStdString();
 
79
  if (substring.length())
 
80
    uiData.setAddress(substring);
 
81
 
 
82
  substring = mainUI.passwd->text().toStdString();
 
83
  if (substring.length())
 
84
    uiData.setPasswd(substring);
 
85
 
 
86
 
 
87
  // Use dynamic binding to add new user to local or remote db
 
88
  int stat = dbcp->putNewUser(uiData);
 
89
  if (stat) {
 
90
    QString tmpStr = QString::fromStdString(dbcp->getErrMsg());
 
91
    QMessageBox::warning(0, "Error in add user form", tmpStr);
 
92
    return;
 
93
  }
 
94
 
 
95
  QMessageBox::information(0, "User Added", "Account name " + 
 
96
                           mainUI.account->text() + " has been added successfully!");
 
97
  mainUI.account->clear();
 
98
  mainUI.name->clear();
 
99
  mainUI.phone->clear();
 
100
  mainUI.email->clear();
 
101
  mainUI.address->clear();
 
102
  mainUI.passwd->clear();
 
103
  mainUI.confirmation->clear();
 
104
}
 
105