Added socket to Package::Source
[dashstudio.git] / src / dashserver / registers / regmanager.cpp
blob52be62b63a2575263fa02d2c0d1035e152f8856a
1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "regmanager.h"
23 #include <QFile>
24 #include <QCryptographicHash>
26 #include <dcore/debug.h>
28 #include "package.h"
30 #include "connection.h"
31 #include "server.h"
33 #include "actionregisteruserparser.h"
35 #include "dashserver/users/usermanager.h"
36 #include "dashserver/users/user.h"
38 #include "dash/network/package/adduser.h"
40 namespace DashServer {
41 namespace Registers {
43 struct Manager::Private
47 Manager::Manager() : DashServer::Observer(),d( new Private)
52 Manager::~Manager()
54 delete d;
58 void Manager::handlePackage(DashServer::Package* const pkg)
60 DashServer::TcpServer *server = pkg->source()->server();
62 if( pkg->root() == "listregisters" )
64 // QString fname = d->db->fileName();
65 //
66 // QFile f(fname);
67 // if( f.exists() )
68 // {
69 // if( f.open(QIODevice::ReadOnly | QIODevice::Text) )
70 // {
71 // pkg->source()->sendToClient(f.readAll());
72 // }
73 // }
75 else if ( pkg->root() == "registeruser" )
77 Parsers::ActionRegisterUserParser parser;
79 if( parser.parse(pkg->xml()))
81 // QHash<QString, QString> data = parser.data();
82 // QString email = data["email"];
83 //
84 // data = d->db->findRegisterByEmail(email);
85 // d->db->removeRegister(email);
86 //
87 // dDebug() << data["login"];
88 //
89 // Users::Manager *manager = server->userManager();
90 //
91 // Users::User user;
92 // user.setLogin(data["login"]);
93 // user.setName(data["name"]);
94 // user.setPassword(QCryptographicHash::hash("", QCryptographicHash::Md5));
95 //
96 // // manager->addUser(user); FIXME
97 //
98 // server->sendToAdmins(pkg->xml());
99 // Packages::AddUser adduser(data["login"], data["name"]);
100 // server->sendToAdmins(adduser.toString());