taskrambler  0.1.8
Web server and task management solution.
application/controller/authenticate/create.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2013 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #define _GNU_SOURCE
24 
25 #include "class.h"
27 #include "session.h"
28 #include "hash.h"
29 #include "auth/credential.h"
30 #include "user.h"
31 
32 #include "utils/memory.h"
33 
34 char * controllerCurrentuserRead(Application, Session, Hash);
35 
36 char *
38  Application application,
39  Session session,
40  Hash args)
41 {
42  HashValue username;
43  HashValue password;
44  Credential credential;
45 
46  char * response_data;
47 
48  username = hashGet(args, CSTRA("username"));
49  password = hashGet(args, CSTRA("password"));
50 
51  if (NULL == username) {
52  username = hashGet(args, CSTRA("email"));
53  }
54 
55  if (NULL == username || NULL == password) {
56  return NULL;
57  }
58 
59  credential = new(Credential,
61  (char *)(username->value), username->nvalue,
62  (char *)(password->value), password->nvalue);
63 
64  if (! applicationLogin(application, credential, session)) {
65  response_data = NULL;
66  } else {
67  response_data = controllerCurrentuserRead(application, session, NULL);
68  }
69 
70  delete(credential);
71 
72  return response_data;
73 }
74 
75 // vim: set ts=4 sw=4:
char * controllerCurrentuserRead(Application, Session, Hash)
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
void * hashGet(Hash, const char *, size_t)
Definition: hash/get.c:51
char * controllerAuthenticateCreate(Application application, Session session, Hash args)
int applicationLogin(Application, Credential, Session)
Definition: login.c:42