check_login_form_submission() factored in separate function

This commit is contained in:
Sergey Lyubka committed 2014-10-09 11:44:12 +01:00
1 parent 5077350589
commit 54ba36c1c9
1 file changed
+9 -6
+9 -6
View File
@@ -40,12 +40,9 @@ static int check_auth(struct mg_connection *conn) {
return MG_FALSE; return MG_FALSE;
} }
static int serve_request(struct mg_connection *conn) { static int check_login_form_submission(struct mg_connection *conn) {
char name[100], password[100], ssid[100], expire[100], expire_epoch[100]; char name[100], password[100], ssid[100], expire[100], expire_epoch[100];
// Always authorize requests to login page
if (strcmp(conn->uri, s_login_uri) == 0 &&
strcmp(conn->request_method, "POST") == 0) {
mg_get_var(conn, "name", name, sizeof(name)); mg_get_var(conn, "name", name, sizeof(name));
mg_get_var(conn, "password", password, sizeof(password)); mg_get_var(conn, "password", password, sizeof(password));
@@ -65,11 +62,17 @@ static int serve_request(struct mg_connection *conn) {
ssid, expire); ssid, expire);
return MG_TRUE; return MG_TRUE;
} }
}
return MG_FALSE; return MG_FALSE;
} }
static int serve_request(struct mg_connection *conn) {
if (strcmp(conn->uri, s_login_uri) == 0 &&
strcmp(conn->request_method, "POST") == 0) {
return check_login_form_submission(conn);
}
return MG_FALSE; // Serve files in the document_root
}
static int ev_handler(struct mg_connection *conn, enum mg_event ev) { static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
switch (ev) { switch (ev) {
case MG_AUTH: return check_auth(conn); case MG_AUTH: return check_auth(conn);