entrance: add login error on wrong password

This commit is contained in:
Michael Bouchaud 2013-09-04 02:10:38 +02:00
parent 4ac6f8a9bf
commit 13ea3f533a
8 changed files with 196 additions and 98 deletions

View File

@ -92,7 +92,7 @@ collections {
visible: 1; visible: 1;
} }
} }
part { name: "entrance.login"; part { name: "entrance.screen";
type: SWALLOW; type: SWALLOW;
description { state: "default" 0.0; description { state: "default" 0.0;
visible: 1; visible: 1;
@ -196,32 +196,6 @@ collections {
} }
} }
/* /*
part { name: "entrance.error";
type: TEXT;
mouse_events: 0;
effect: SOFT_SHADOW;
scale: 1;
description { state: "default" 0.0;
color: 255 255 255 0;
fixed: 1 1;
rel1.to_y: "entrance.xsessions";
rel1.relative: 0.0 1.0;
align: 0.5 0.0;
text {
text: "Error on login ! Maybe wrong password ?";
font: "Sans";
size: 18;
min: 1 1;
align: 0.5 0.5;
}
}
description { state: "visible" 0.0;
inherit: "default" 0.0;
rel1.offset: 0 50;
rel2.offset: 0 50;
color: 255 255 255 255;
}
}
*/ */
} }
programs { programs {
@ -274,6 +248,18 @@ collections {
group { group {
name : "entrance/login"; name : "entrance/login";
parts { parts {
part {
name: "error";
type: RECT;
description { state: "default" 0.0;
color: 255 0 0 96;
visible: 0;
}
description { state: "visible" 0.0;
inherit: "default" 0.0;
visible: 1;
}
}
part { part {
name: "entrance.login"; name: "entrance.login";
type: SWALLOW; type: SWALLOW;
@ -293,7 +279,6 @@ collections {
name: "entrance.password"; name: "entrance.password";
type: SWALLOW; type: SWALLOW;
repeat_events: 0; repeat_events: 0;
source: "entrance/entry/password";
description { description {
state: "default" 0.0; state: "default" 0.0;
min: 140 0; min: 140 0;
@ -316,9 +301,39 @@ collections {
visible: 1; visible: 1;
} }
} }
part { name: "entrance.error";
type: TEXT;
mouse_events: 0;
effect: SOFT_SHADOW;
scale: 1;
description { state: "default" 0.0;
visible: 0;
color: 255 255 255 0;
fixed: 1 1;
rel1.to_y: "entrance.xsessions";
rel1.relative: 0.0 1.0;
align: 0.5 0.0;
rel1.offset: 0 50;
rel2.offset: -1 51;
text {
text: "Error on login ! Maybe wrong password ?";
font: "Sans";
size: 18;
min: 1 1;
align: 0.5 0.5;
}
}
description { state: "visible" 0.0;
inherit: "default" 0.0;
visible: 1;
color: 255 255 255 255;
}
}
/* /*
*
* PROGRAMS * PROGRAMS
*
*/ */
programs { programs {
program { program {
@ -335,30 +350,24 @@ collections {
action: STATE_SET "default" 0.0; action: STATE_SET "default" 0.0;
target: "entrance.xsessions"; target: "entrance.xsessions";
} }
}
/*
*
* PROGRAMS
*
programs {
program { program {
name: "login_error"; name: "login_error";
signal: "entrance,auth,error"; signal: "entrance,auth,error";
source: ""; source: "";
action: STATE_SET "visible" 0.0; action: STATE_SET "visible" 0.0;
transition: DECELERATE 0.2; target: "error";
target: "entrance.error"; target: "entrance.error";
} }
program { program {
name: "login_change"; name: "login_change";
signal: "entrance.auth.change"; signal: "entrance,auth,changed";
source: ""; source: "";
action: STATE_SET "default" 0.0; action: STATE_SET "default" 0.0;
transition: ACCELERATE 0.4; target: "error";
target: "entrance.error"; target: "entrance.error";
} }
}
/*
program { program {
name: "auth_enable"; name: "auth_enable";
@ -389,6 +398,8 @@ collections {
transition: LINEAR 0.7; transition: LINEAR 0.7;
target: "clip"; target: "clip";
} }
* If you want check auth, emit this signal "entrance.auth.request" ""
* Here is an example
program { program {
name: "login_valid"; name: "login_valid";
signal: "mouse,down,*"; signal: "mouse,down,*";

View File

@ -60,19 +60,22 @@ main(int argc, char **argv)
elm_init(argc, argv); elm_init(argc, argv);
PT("login init\n"); PT("login init\n");
entrance_login_init(); entrance_login_init();
PT("client init\n"); PT("gui init\n");
if (!entrance_gui_init(theme)) return EXIT_FAILURE; if (!entrance_gui_init(theme)) return EXIT_FAILURE;
PT("client run\n"); PT("connect init\n");
entrance_connect_init(); entrance_connect_init();
elm_run(); elm_run();
PT("connect shutdown\n");
entrance_connect_shutdown(); entrance_connect_shutdown();
PT("_client: client shutdown\n"); PT("gui shutdown\n");
entrance_gui_shutdown(); entrance_gui_shutdown();
PT("login shutdown\n");
entrance_login_shutdown(); entrance_login_shutdown();
elm_shutdown(); elm_shutdown();
ecore_x_shutdown(); ecore_x_shutdown();
ecore_shutdown(); ecore_shutdown();
eina_shutdown(); eina_shutdown();
PT("exit\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,13 +1,19 @@
#include <Ecore_Con.h> #include <Ecore_Con.h>
#include "entrance_client.h" #include "entrance_client.h"
typedef struct
{
Entrance_Connect_Auth_Cb func;
void *data;
} Entrance_Connect_Auth;
static Eina_Bool _entrance_connect_add(void *data, int type, void *event); static Eina_Bool _entrance_connect_add(void *data, int type, void *event);
static Eina_Bool _entrance_connect_del(void *data, int type, void *event); static Eina_Bool _entrance_connect_del(void *data, int type, void *event);
static Eina_Bool _entrance_connect_data(void *data, int type, void *event); static Eina_Bool _entrance_connect_data(void *data, int type, void *event);
Ecore_Con_Server *_entrance_connect; static Ecore_Con_Server *_entrance_connect;
Eina_List *_handlers; static Eina_List *_handlers = NULL;
static Eina_List *_auth_list = NULL;
static Eina_Bool static Eina_Bool
_entrance_connect_add(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) _entrance_connect_add(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
@ -36,6 +42,19 @@ _entrance_connect_data(void *data __UNUSED__, int type __UNUSED__, void *event)
return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_RENEW;
} }
static void
_entrance_connect_auth(Eina_Bool granted)
{
Entrance_Connect_Auth *auth;
Eina_List *l, *ll;
EINA_LIST_FOREACH_SAFE(_auth_list, l, ll, auth)
{
if (auth->func)
auth->func(auth->data, granted);
}
}
static Eina_Bool static Eina_Bool
_entrance_connect_read_cb(const void *data, size_t size EINA_UNUSED, void *user_data EINA_UNUSED) _entrance_connect_read_cb(const void *data, size_t size EINA_UNUSED, void *user_data EINA_UNUSED)
{ {
@ -46,15 +65,10 @@ _entrance_connect_read_cb(const void *data, size_t size EINA_UNUSED, void *user_
if (eev->type == ENTRANCE_EVENT_STATUS) if (eev->type == ENTRANCE_EVENT_STATUS)
{ {
if (eev->event.status.granted) if (eev->event.status.granted)
{
PT("Auth granted :)\n"); PT("Auth granted :)\n");
entrance_gui_auth_valid();
}
else else
{
PT("Auth error :(\n"); PT("Auth error :(\n");
entrance_gui_auth_error(); _entrance_connect_auth(eev->event.status.granted);
}
} }
else if (eev->type == ENTRANCE_EVENT_MAXTRIES) else if (eev->type == ENTRANCE_EVENT_MAXTRIES)
{ {
@ -135,6 +149,24 @@ entrance_connect_conf_send(Entrance_Conf_Gui_Event *ev)
entrance_event_send(&eev); entrance_event_send(&eev);
} }
void *
entrance_connect_auth_cb_add(Entrance_Connect_Auth_Cb func, void *data)
{
PT("auth handler add\n");
Entrance_Connect_Auth *auth;
auth = malloc(sizeof(Entrance_Connect_Auth));
auth->func = func;
auth->data = data;
_auth_list = eina_list_append(_auth_list, auth);
return auth;
}
void
entrance_connect_auth_cb_del(void *auth)
{
PT("auth handler remove\n");
_auth_list = eina_list_remove(_auth_list, auth);
}
void void
entrance_connect_init() entrance_connect_init()
@ -165,7 +197,6 @@ void
entrance_connect_shutdown() entrance_connect_shutdown()
{ {
Ecore_Event_Handler *h; Ecore_Event_Handler *h;
PT("client server shutdown\n");
EINA_LIST_FREE(_handlers, h) EINA_LIST_FREE(_handlers, h)
ecore_event_handler_del(h); ecore_event_handler_del(h);
entrance_event_shutdown(); entrance_event_shutdown();

View File

@ -1,8 +1,13 @@
#ifndef ENTRANCE_CONNECT_ #ifndef ENTRANCE_CONNECT_
#define ENTRANCE_CONNECT_ #define ENTRANCE_CONNECT_
typedef void (*Entrance_Connect_Auth_Cb)(void *data, Eina_Bool granted);
void entrance_connect_init(); void entrance_connect_init();
void entrance_connect_auth_send(const char *login, const char *password, const char *session, Eina_Bool open_session); void entrance_connect_auth_send(const char *login, const char *password, const char *session, Eina_Bool open_session);
void entrance_connect_action_send(unsigned char id); void entrance_connect_action_send(unsigned char id);
void entrance_connect_conf_send(Entrance_Conf_Gui_Event *conf); void entrance_connect_conf_send(Entrance_Conf_Gui_Event *conf);
void *entrance_connect_auth_cb_add(Entrance_Connect_Auth_Cb func, void *data);
void entrance_connect_auth_cb_del(void *list);
void entrance_connect_shutdown(); void entrance_connect_shutdown();
#endif /* ENTRANCE_CONNECT_ */ #endif /* ENTRANCE_CONNECT_ */

View File

@ -99,7 +99,7 @@ _entrance_fill_gengrid(Evas_Object *obj, Entrance_Fill *ef, Eina_List *contents,
///////////////// HOVERSEL ///////////////////////////// ///////////////// HOVERSEL /////////////////////////////
static void static void
_entrance_fill_hoversell_func_cb(void *data, Evas_Object *obj, void *event_info) _entrance_fill_hoversell_func_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info)
{ {
Entrance_Fill *ef; Entrance_Fill *ef;

View File

@ -14,6 +14,7 @@ static void _entrance_gui_user_del(void *data, Evas_Object *obj);
static void _entrance_gui_actions_populate(); static void _entrance_gui_actions_populate();
static void _entrance_gui_conf_clicked_cb(void *data, Evas_Object *obj, void *event_info); static void _entrance_gui_conf_clicked_cb(void *data, Evas_Object *obj, void *event_info);
static void _entrance_gui_update(void); static void _entrance_gui_update(void);
static void _entrance_gui_auth_cb(void *data, Eina_Bool granted);
/* /*
@ -118,8 +119,8 @@ entrance_gui_init(const char *theme)
fprintf(stderr, "%s\n", "entrance"); fprintf(stderr, "%s\n", "entrance");
return j; return j;
} }
elm_object_part_content_set(o, "entrance.login", ol); elm_object_part_content_set(o, "entrance.screen", ol);
o = entrance_login_add(ol); o = entrance_login_add(ol, _entrance_gui_auth_cb, screen);
entrance_login_open_session_set(o, EINA_TRUE); entrance_login_open_session_set(o, EINA_TRUE);
screen->login = o; screen->login = o;
elm_object_part_content_set(ol, "entrance.login", o); elm_object_part_content_set(ol, "entrance.login", o);
@ -245,40 +246,6 @@ entrance_gui_stringlist_free(Eina_List *list)
eina_stringshare_del(s); eina_stringshare_del(s);
} }
void
entrance_gui_auth_valid()
{
Eina_List *l;
Entrance_Screen *screen;
EINA_LIST_FOREACH(_gui->screens, l, screen)
{
edje_object_signal_emit(elm_layout_edje_get(screen->edj),
"entrance,auth,valid", "");
}
/*
_gui_login_timeout = ecore_timer_add(10.0,
_entrance_gui_login_timeout,
screen);
*/
}
void
entrance_gui_auth_error()
{
/*
Evas_Object *o;
Eina_List *l;
Entrance_Screen *screen;
EINA_LIST_FOREACH(_gui->screens, l, screen)
{
o = ENTRANCE_GUI_GET(screen->edj, "entrance.password");
elm_entry_entry_set(o, "");
edje_object_signal_emit(elm_layout_edje_get(screen->edj),
"entrance,auth,error", "");
}
*/
}
void void
entrance_gui_actions_set(Eina_List *actions) entrance_gui_actions_set(Eina_List *actions)
@ -329,7 +296,7 @@ entrance_gui_users_set(Eina_List *users)
ol = ENTRANCE_GUI_GET(screen->edj, "entrance.users"); ol = ENTRANCE_GUI_GET(screen->edj, "entrance.users");
if (!ol) continue; if (!ol) continue;
entrance_fill(ol, ef, users, _entrance_gui_user_sel_cb, screen->login); entrance_fill(ol, ef, users, _entrance_gui_user_sel_cb, screen->login);
edje_object_signal_emit(elm_layout_edje_get(screen->edj), elm_object_signal_emit(screen->edj,
"entrance,users,enabled", ""); "entrance,users,enabled", "");
} }
_gui->users = users; _gui->users = users;
@ -882,6 +849,32 @@ _entrance_gui_actions_populate()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static void
_entrance_gui_auth_cb(void *data, Eina_Bool granted)
{
Eina_List *l;
Entrance_Screen *screen;
EINA_LIST_FOREACH(_gui->screens, l, screen)
{
if (granted)
{
elm_object_signal_emit(screen->edj,
"entrance,auth,valid", "");
}
else
{
elm_object_signal_emit(screen->edj,
"entrance,auth,error", "");
}
}
/*
if (granted)
_gui_login_timeout = ecore_timer_add(10.0,
_entrance_gui_login_timeout,
data);
*/
}
static Eina_Bool static Eina_Bool
_entrance_gui_cb_window_property(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info) _entrance_gui_cb_window_property(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)

View File

@ -19,6 +19,7 @@ static void _login_password_focused_cb(void *data, Evas_Object *obj, void *event
static void _login_password_unfocused_cb(void *data, Evas_Object *obj, void *event); static void _login_password_unfocused_cb(void *data, Evas_Object *obj, void *event);
static void _login_login_activated_cb(void *data, Evas_Object *obj, void *event); static void _login_login_activated_cb(void *data, Evas_Object *obj, void *event);
static char *_login_xsession_text_get(void *data, Evas_Object *obj, const char *part); static char *_login_xsession_text_get(void *data, Evas_Object *obj, const char *part);
static void _login_auth_cb(void *data, Eina_Bool granted);
static Entrance_Fill *_login_fill; static Entrance_Fill *_login_fill;
@ -27,9 +28,16 @@ struct Entrance_Login_
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
char passwd[ENTRANCE_PASSWD_LEN]; char passwd[ENTRANCE_PASSWD_LEN];
Entrance_Xsession *session; Entrance_Xsession *session;
struct
{
Entrance_Login_Cb login;
void *data;
} func;
void *auth;
Eina_Bool open_session : 1; Eina_Bool open_session : 1;
Eina_Bool selected : 1; Eina_Bool selected : 1;
Eina_Bool catch : 1; Eina_Bool catch : 1;
Eina_Bool wait : 1;
}; };
#define LOGIN_GET(widget) \ #define LOGIN_GET(widget) \
@ -116,6 +124,9 @@ _login_check_auth(Evas_Object *widget)
o = elm_object_part_content_get(widget, "entrance.login"); o = elm_object_part_content_get(widget, "entrance.login");
host = elm_entry_markup_to_utf8(elm_object_text_get(o)); host = elm_entry_markup_to_utf8(elm_object_text_get(o));
login->wait = EINA_TRUE;
if (!login->auth)
login->auth = entrance_connect_auth_cb_add(_login_auth_cb, widget);
if (login->session) if (login->session)
entrance_connect_auth_send(host, login->passwd, entrance_connect_auth_send(host, login->passwd,
login->session->name, login->session->name,
@ -154,6 +165,13 @@ _login_key_down_cb(void *data, int type EINA_UNUSED, void *event)
LOGIN_GET(data) ECORE_CALLBACK_PASS_ON; LOGIN_GET(data) ECORE_CALLBACK_PASS_ON;
ev = event; ev = event;
elm_object_signal_emit(data,
"entrance,auth,changed", "");
elm_object_signal_emit(elm_object_part_content_get(data,
"entrance.password"),
"entrance,auth,changed", "");
if (!strcmp(ev->key, "KP_Enter")) if (!strcmp(ev->key, "KP_Enter"))
{ {
_login_check_auth(data); _login_check_auth(data);
@ -276,13 +294,50 @@ _login_xsession_update(Evas_Object *obj)
} }
static void static void
_login_xsession_clicked_cb(void *data, Evas_Object *obj, void *event_info) _login_xsession_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{ {
LOGIN_GET(data); LOGIN_GET(data);
login->session = elm_object_item_data_get(event_info); login->session = elm_object_item_data_get(event_info);
_login_xsession_update(data); _login_xsession_update(data);
} }
static void
_login_auth_cb(void *data, Eina_Bool granted)
{
LOGIN_GET(data);
if (login->wait)
{
if (login->func.login)
login->func.login(login->func.data, granted);
login->wait = EINA_FALSE;
entrance_connect_auth_cb_del(login->auth);
login->auth = NULL;
if (!granted)
{
elm_object_signal_emit(data,
"entrance,auth,error", "");
elm_object_signal_emit(
elm_object_part_content_get(data, "entrance.login"),
"entrance,auth,error", "login");
elm_object_signal_emit(
elm_object_part_content_get(data, "entrance.password"),
"entrance,auth,error", "password");
}
else
{
elm_object_signal_emit(data,
"entrance,auth,valid", "");
elm_object_signal_emit(
elm_object_part_content_get(data, "entrance.login"),
"entrance,auth,valid", "login");
elm_object_signal_emit(
elm_object_part_content_get(data, "entrance.password"),
"entrance,auth,valid", "password");
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void void
@ -302,14 +357,16 @@ entrance_login_shutdown(void)
} }
Evas_Object * Evas_Object *
entrance_login_add(Evas_Object *obj) entrance_login_add(Evas_Object *obj, Entrance_Login_Cb login_cb, void *data)
{ {
Evas_Object *o, *h, *p; Evas_Object *o, *h, *p;
Entrance_Login *login; Entrance_Login *login;
/* layout */ /* layout */
o = entrance_gui_theme_get(obj, "entrance/login");
login = calloc(1, sizeof(Entrance_Login)); login = calloc(1, sizeof(Entrance_Login));
login->func.login = login_cb;
login->func.data = data;
o = entrance_gui_theme_get(obj, "entrance/login");
evas_object_data_set(o, "entrance", login); evas_object_data_set(o, "entrance", login);
@ -376,7 +433,6 @@ void
entrance_login_session_set(Evas_Object *widget, const char *name) entrance_login_session_set(Evas_Object *widget, const char *name)
{ {
Entrance_Xsession *sess; Entrance_Xsession *sess;
Evas_Object *o;
const Eina_List *l = NULL; const Eina_List *l = NULL;
LOGIN_GET(widget); LOGIN_GET(widget);
if (name) if (name)
@ -392,7 +448,6 @@ entrance_login_session_set(Evas_Object *widget, const char *name)
} }
if (l) if (l)
login->session = sess; login->session = sess;
o = elm_object_part_content_get(widget, "entrance.xsessions");
_login_xsession_update(widget); _login_xsession_update(widget);
} }

View File

@ -5,7 +5,7 @@ typedef void (*Entrance_Login_Cb) (void *data, Eina_Bool granted);
void entrance_login_init(void); void entrance_login_init(void);
void entrance_login_shutdown(void); void entrance_login_shutdown(void);
Evas_Object *entrance_login_add(Evas_Object *win); Evas_Object *entrance_login_add(Evas_Object *win, Entrance_Login_Cb login_cb, void *data);
void entrance_login_xsessions_populate(Evas_Object *widget, Eina_List *xsessions); void entrance_login_xsessions_populate(Evas_Object *widget, Eina_List *xsessions);
void entrance_login_login_set(Evas_Object *widget, const char *user); void entrance_login_login_set(Evas_Object *widget, const char *user);
void entrance_login_session_set(Evas_Object *widget, const char *user); void entrance_login_session_set(Evas_Object *widget, const char *user);