Skip to content

Commit

Permalink
User delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsevillamol committed May 5, 2015
1 parent bce844c commit a362822
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion fdimail/fdimail/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class List
bool insert(T* const elem);
bool search(const std::string &id, int &pos) const;
T* get(const std::string &id);
bool destroy(const std::string &id);

bool destroy(const std::string &id); //Deletes the pointers

void save(const std::string &name);
bool load(const std::string &name/*, const std::string &url*/);

Expand Down
15 changes: 15 additions & 0 deletions fdimail/fdimail/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ User* Manager::createAccount()
}
}

bool Manager::deleteAccount(std::string &id){
User* user = userList.get(id);
if (user != nullptr){
//Delete inbox
for (int i = 0; i < user->getInbox()->length(); i++){
mailList.delete_mail(user->getInbox()->operator[](i)->getId());
}
//Delete outbox
for (int i = 0; i < user->getOutbox()->length(); i++){
mailList.delete_mail(user->getOutbox()->operator[](i)->getId());
}
userList.delete_user(id);
}
}

void Manager::sendMail(User* user, Mail* mail)
{
//Add to database
Expand Down
2 changes: 2 additions & 0 deletions fdimail/fdimail/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Manager
User* registerUser();
User* createAccount();

bool deleteAccount(std::string &id);

MailList* getMailList(){ return &mailList; }

void sendMail(User* user, Mail* mail);
Expand Down
14 changes: 13 additions & 1 deletion fdimail/fdimail/UserList.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
#include "List.h"
#include "User.h"

class UserList: public List<User, MAX_USERS> {};
class UserList: public List<User, MAX_USERS> {
public:
bool delete_user(std::string &id){
int pos;
if (search(id, pos)){
delete list[pos];
shiftLeft(pos);
return true;
}
else return false;
}

};

#endif

0 comments on commit a362822

Please sign in to comment.