Merge lp:~azzar1/unity/fix-missing-entry-lockscreen into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4257
Proposed branch: lp:~azzar1/unity/fix-missing-entry-lockscreen
Merge into: lp:unity
Diff against target: 558 lines (+144/-86)
12 files modified
lockscreen/KylinUserPromptView.cpp (+15/-15)
lockscreen/KylinUserPromptView.h (+2/-3)
lockscreen/LockScreenAbstractPromptView.h (+5/-3)
lockscreen/LockScreenController.cpp (+3/-1)
lockscreen/LockScreenController.h (+2/-0)
lockscreen/LockScreenPromptFactory.cpp (+4/-3)
lockscreen/LockScreenPromptFactory.h (+3/-1)
lockscreen/UserAuthenticator.h (+2/-0)
lockscreen/UserAuthenticatorPam.cpp (+41/-33)
lockscreen/UserAuthenticatorPam.h (+9/-8)
lockscreen/UserPromptView.cpp (+51/-15)
lockscreen/UserPromptView.h (+7/-4)
To merge this branch: bzr merge lp:~azzar1/unity/fix-missing-entry-lockscreen
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+330801@code.launchpad.net

Commit message

Refactor the way UserAuthenticator is created and passed around. Handle failures to create new threads and fallback to a "Switch to greeter..." button in case of failure.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good, thanks

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lockscreen/KylinUserPromptView.cpp'
--- lockscreen/KylinUserPromptView.cpp 2016-03-31 05:57:11 +0000
+++ lockscreen/KylinUserPromptView.cpp 2017-09-15 13:37:27 +0000
@@ -79,9 +79,9 @@
7979
80}80}
8181
82KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_manager)82KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_manager,
83 : AbstractUserPromptView(session_manager)83 UserAuthenticator::Ptr const& user_authenticator)
84 , session_manager_(session_manager)84 : AbstractUserPromptView(session_manager, user_authenticator)
85 , username_(nullptr)85 , username_(nullptr)
86 , msg_layout_(nullptr)86 , msg_layout_(nullptr)
87 , prompt_layout_(nullptr)87 , prompt_layout_(nullptr)
@@ -90,25 +90,25 @@
90 , avatar_(nullptr)90 , avatar_(nullptr)
91 , avatar_icon_file("")91 , avatar_icon_file("")
92{92{
93 user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){93 user_authenticator_->echo_on_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){
94 AddPrompt(message, true, promise);94 AddPrompt(message, true, promise);
95 });95 }, *this));
9696
97 user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){97 user_authenticator_->echo_off_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){
98 AddPrompt(message, false, promise);98 AddPrompt(message, false, promise);
99 });99 }, *this));
100100
101 user_authenticator_.message_requested.connect([this](std::string const& message){101 user_authenticator_->message_requested.connect(sigc::track_obj([this](std::string const& message){
102 AddMessage(message, nux::color::White);102 AddMessage(message, nux::color::White);
103 });103 }, *this));
104104
105 user_authenticator_.error_requested.connect([this](std::string const& message){105 user_authenticator_->error_requested.connect(sigc::track_obj([this](std::string const& message){
106 AddMessage(message, nux::color::Red);106 AddMessage(message, nux::color::Red);
107 });107 }, *this));
108108
109 user_authenticator_.clear_prompts.connect([this](){109 user_authenticator_->clear_prompts.connect(sigc::track_obj([this](){
110 ResetLayout();110 ResetLayout();
111 });111 }, *this));
112112
113 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &KylinUserPromptView::UpdateSize)));113 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &KylinUserPromptView::UpdateSize)));
114114
@@ -121,7 +121,7 @@
121 ResetLayout();121 ResetLayout();
122122
123 TextureCache::GetDefault().themed_invalidated.connect(sigc::mem_fun(this, &KylinUserPromptView::ResetLayout));123 TextureCache::GetDefault().themed_invalidated.connect(sigc::mem_fun(this, &KylinUserPromptView::ResetLayout));
124 user_authenticator_.AuthenticateStart(session_manager_->UserName(),124 user_authenticator_->AuthenticateStart(session_manager_->UserName(),
125 sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb));125 sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb));
126}126}
127127
@@ -244,7 +244,7 @@
244 {244 {
245 AddMessage(_("Invalid password, please try again"), nux::color::Red);245 AddMessage(_("Invalid password, please try again"), nux::color::Red);
246246
247 user_authenticator_.AuthenticateStart(session_manager_->UserName(),247 user_authenticator_->AuthenticateStart(session_manager_->UserName(),
248 sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb));248 sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb));
249 }249 }
250}250}
251251
=== modified file 'lockscreen/KylinUserPromptView.h'
--- lockscreen/KylinUserPromptView.h 2016-03-16 10:47:16 +0000
+++ lockscreen/KylinUserPromptView.h 2017-09-15 13:37:27 +0000
@@ -44,7 +44,8 @@
44class KylinUserPromptView : public AbstractUserPromptView44class KylinUserPromptView : public AbstractUserPromptView
45{45{
46public:46public:
47 KylinUserPromptView(session::Manager::Ptr const& session_manager);47 KylinUserPromptView(session::Manager::Ptr const& session_manager,
48 UserAuthenticator::Ptr const& user_authenticator);
4849
49 nux::View* focus_view();50 nux::View* focus_view();
5051
@@ -62,8 +63,6 @@
62 nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(std::string const& icon_file, int icon_size);63 nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(std::string const& icon_file, int icon_size);
6364
64private:65private:
65 session::Manager::Ptr session_manager_;
66 UserAuthenticatorPam user_authenticator_;
67 StaticCairoText* username_;66 StaticCairoText* username_;
68 nux::VLayout* msg_layout_;67 nux::VLayout* msg_layout_;
69 nux::VLayout* prompt_layout_;68 nux::VLayout* prompt_layout_;
7069
=== modified file 'lockscreen/LockScreenAbstractPromptView.h'
--- lockscreen/LockScreenAbstractPromptView.h 2016-03-31 09:51:33 +0000
+++ lockscreen/LockScreenAbstractPromptView.h 2017-09-15 13:37:27 +0000
@@ -29,7 +29,7 @@
29#include <Nux/VLayout.h>29#include <Nux/VLayout.h>
30#include "UnityCore/SessionManager.h"30#include "UnityCore/SessionManager.h"
3131
32#include "UserAuthenticatorPam.h"32#include "UserAuthenticator.h"
33#include "unity-shared/IMTextEntry.h"33#include "unity-shared/IMTextEntry.h"
3434
35namespace nux35namespace nux
@@ -48,10 +48,12 @@
48class AbstractUserPromptView : public nux::View48class AbstractUserPromptView : public nux::View
49{49{
50public:50public:
51 AbstractUserPromptView(session::Manager::Ptr const& session_manager)51 AbstractUserPromptView(session::Manager::Ptr const& session_manager,
52 UserAuthenticator::Ptr const& user_authenticator)
52 : nux::View(NUX_TRACKER_LOCATION)53 : nux::View(NUX_TRACKER_LOCATION)
53 , scale(1.0)54 , scale(1.0)
54 , session_manager_(session_manager)55 , session_manager_(session_manager)
56 , user_authenticator_(user_authenticator)
55 {}57 {}
5658
57 nux::Property<double> scale;59 nux::Property<double> scale;
@@ -64,7 +66,7 @@
6466
65protected:67protected:
66 session::Manager::Ptr session_manager_;68 session::Manager::Ptr session_manager_;
67 UserAuthenticatorPam user_authenticator_;69 UserAuthenticator::Ptr user_authenticator_;
68 std::shared_ptr<nux::AbstractPaintLayer> bg_layer_;70 std::shared_ptr<nux::AbstractPaintLayer> bg_layer_;
69 StaticCairoText* username_;71 StaticCairoText* username_;
70 nux::VLayout* msg_layout_;72 nux::VLayout* msg_layout_;
7173
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2016-11-11 16:00:53 +0000
+++ lockscreen/LockScreenController.cpp 2017-09-15 13:37:27 +0000
@@ -27,6 +27,7 @@
27#include "LockScreenPromptFactory.h"27#include "LockScreenPromptFactory.h"
28#include "LockScreenShield.h"28#include "LockScreenShield.h"
29#include "LockScreenSettings.h"29#include "LockScreenSettings.h"
30#include "UserAuthenticatorPam.h"
30#include "unity-shared/AnimationUtils.h"31#include "unity-shared/AnimationUtils.h"
31#include "unity-shared/InputMonitor.h"32#include "unity-shared/InputMonitor.h"
32#include "unity-shared/UnitySettings.h"33#include "unity-shared/UnitySettings.h"
@@ -70,6 +71,7 @@
70 , upstart_wrapper_(upstart_wrapper)71 , upstart_wrapper_(upstart_wrapper)
71 , shield_factory_(shield_factory)72 , shield_factory_(shield_factory)
72 , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>())73 , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>())
74 , user_authenticator_(std::make_shared<UserAuthenticatorPam>())
73 , fade_animator_(unity::Settings::Instance().low_gfx() ? 0 : LOCK_FADE_DURATION)75 , fade_animator_(unity::Settings::Instance().low_gfx() ? 0 : LOCK_FADE_DURATION)
74 , blank_window_animator_(IDLE_FADE_DURATION)76 , blank_window_animator_(IDLE_FADE_DURATION)
75 , test_mode_(test_mode)77 , test_mode_(test_mode)
@@ -259,7 +261,7 @@
259261
260 if (!prompt_view)262 if (!prompt_view)
261 {263 {
262 prompt_view = test_mode_ ? nux::ObjectPtr<AbstractUserPromptView>() : PromptFactory::CreatePrompt(session_manager_);264 prompt_view = test_mode_ ? nux::ObjectPtr<AbstractUserPromptView>() : PromptFactory::CreatePrompt(session_manager_, user_authenticator_);
263 prompt_view_ = prompt_view.GetPointer();265 prompt_view_ = prompt_view.GetPointer();
264 }266 }
265267
266268
=== modified file 'lockscreen/LockScreenController.h'
--- lockscreen/LockScreenController.h 2016-11-11 16:00:53 +0000
+++ lockscreen/LockScreenController.h 2017-09-15 13:37:27 +0000
@@ -29,6 +29,7 @@
29#include "LockScreenAcceleratorController.h"29#include "LockScreenAcceleratorController.h"
30#include "SuspendInhibitorManager.h"30#include "SuspendInhibitorManager.h"
31#include "ScreenSaverDBusManager.h"31#include "ScreenSaverDBusManager.h"
32#include "UserAuthenticator.h"
32#include "unity-shared/BackgroundEffectHelper.h"33#include "unity-shared/BackgroundEffectHelper.h"
33#include "unity-shared/SystemdWrapper.h"34#include "unity-shared/SystemdWrapper.h"
34#include "unity-shared/UpstartWrapper.h"35#include "unity-shared/UpstartWrapper.h"
@@ -95,6 +96,7 @@
95 UpstartWrapper::Ptr upstart_wrapper_;96 UpstartWrapper::Ptr upstart_wrapper_;
96 ShieldFactoryInterface::Ptr shield_factory_;97 ShieldFactoryInterface::Ptr shield_factory_;
97 SuspendInhibitorManager::Ptr suspend_inhibitor_manager_;98 SuspendInhibitorManager::Ptr suspend_inhibitor_manager_;
99 UserAuthenticator::Ptr user_authenticator_;
98100
99 nux::animation::AnimateValue<double> fade_animator_;101 nux::animation::AnimateValue<double> fade_animator_;
100 nux::animation::AnimateValue<double> blank_window_animator_;102 nux::animation::AnimateValue<double> blank_window_animator_;
101103
=== modified file 'lockscreen/LockScreenPromptFactory.cpp'
--- lockscreen/LockScreenPromptFactory.cpp 2015-12-04 08:17:46 +0000
+++ lockscreen/LockScreenPromptFactory.cpp 2017-09-15 13:37:27 +0000
@@ -26,14 +26,15 @@
26{26{
27namespace lockscreen27namespace lockscreen
28{28{
29nux::ObjectPtr<AbstractUserPromptView> PromptFactory::CreatePrompt(session::Manager::Ptr const& sm)29nux::ObjectPtr<AbstractUserPromptView> PromptFactory::CreatePrompt(session::Manager::Ptr const& sm,
30 UserAuthenticator::Ptr const& ua)
30{31{
31 nux::ObjectPtr<AbstractUserPromptView> prompt;32 nux::ObjectPtr<AbstractUserPromptView> prompt;
3233
33 if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)34 if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
34 prompt = new KylinUserPromptView(sm);35 prompt = new KylinUserPromptView(sm, ua);
35 else36 else
36 prompt = new UserPromptView(sm);37 prompt = new UserPromptView(sm, ua);
3738
38 return prompt;39 return prompt;
39}40}
4041
=== modified file 'lockscreen/LockScreenPromptFactory.h'
--- lockscreen/LockScreenPromptFactory.h 2016-03-31 09:51:33 +0000
+++ lockscreen/LockScreenPromptFactory.h 2017-09-15 13:37:27 +0000
@@ -22,6 +22,7 @@
2222
23#include <NuxCore/NuxCore.h>23#include <NuxCore/NuxCore.h>
24#include "UnityCore/SessionManager.h"24#include "UnityCore/SessionManager.h"
25#include "UserAuthenticator.h"
2526
26namespace unity27namespace unity
27{28{
@@ -33,7 +34,8 @@
3334
34struct PromptFactory35struct PromptFactory
35{36{
36 static nux::ObjectPtr<AbstractUserPromptView> CreatePrompt(session::Manager::Ptr const&);37 static nux::ObjectPtr<AbstractUserPromptView> CreatePrompt(session::Manager::Ptr const&,
38 UserAuthenticator::Ptr const&);
37};39};
3840
39}41}
4042
=== modified file 'lockscreen/UserAuthenticator.h'
--- lockscreen/UserAuthenticator.h 2014-03-05 04:09:13 +0000
+++ lockscreen/UserAuthenticator.h 2017-09-15 13:37:27 +0000
@@ -36,6 +36,7 @@
36class UserAuthenticator36class UserAuthenticator
37{37{
38public:38public:
39 typedef std::shared_ptr<UserAuthenticator> Ptr;
39 typedef std::function<void(bool)> AuthenticateEndCallback;40 typedef std::function<void(bool)> AuthenticateEndCallback;
4041
41 virtual ~UserAuthenticator() = default;42 virtual ~UserAuthenticator() = default;
@@ -43,6 +44,7 @@
43 // Authenticate the user in a background thread.44 // Authenticate the user in a background thread.
44 virtual bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) = 0;45 virtual bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) = 0;
4546
47 sigc::signal<void> start_failed;
46 sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_on_requested;48 sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_on_requested;
47 sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_off_requested;49 sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_off_requested;
48 sigc::signal<void, std::string> message_requested;50 sigc::signal<void, std::string> message_requested;
4951
=== modified file 'lockscreen/UserAuthenticatorPam.cpp'
--- lockscreen/UserAuthenticatorPam.cpp 2016-08-10 08:56:27 +0000
+++ lockscreen/UserAuthenticatorPam.cpp 2017-09-15 13:37:27 +0000
@@ -23,6 +23,7 @@
2323
24#include "UserAuthenticatorPam.h"24#include "UserAuthenticatorPam.h"
25#include "unity-shared/UnitySettings.h"25#include "unity-shared/UnitySettings.h"
26#include "UnityCore/GLibWrapper.h"
2627
27#include <cstring>28#include <cstring>
28#include <security/pam_appl.h>29#include <security/pam_appl.h>
@@ -36,42 +37,49 @@
36bool UserAuthenticatorPam::AuthenticateStart(std::string const& username,37bool UserAuthenticatorPam::AuthenticateStart(std::string const& username,
37 AuthenticateEndCallback const& authenticate_cb)38 AuthenticateEndCallback const& authenticate_cb)
38{39{
40 if (pam_handle_)
41 return false;
42
39 first_prompt_ = true;43 first_prompt_ = true;
40 username_ = username;44 username_ = username;
41 authenticate_cb_ = authenticate_cb;45 authenticate_cb_ = authenticate_cb;
42 pam_handle_ = nullptr;46
4347 glib::Error error;
44 if (!InitPam() || !pam_handle_)48 g_thread_try_new(nullptr, AuthenticationThreadFunc, this, &error);
45 return false;49
4650 return !error;
47 glib::Object<GTask> task(g_task_new(nullptr, cancellable_, [] (GObject*, GAsyncResult*, gpointer data) {51}
48 auto self = static_cast<UserAuthenticatorPam*>(data);52
49 pam_end(self->pam_handle_, self->status_);53gpointer UserAuthenticatorPam::AuthenticationThreadFunc(gpointer data)
50 self->authenticate_cb_(self->status_ == PAM_SUCCESS);54{
51 }, this));55 auto self = static_cast<UserAuthenticatorPam*>(data);
5256
53 g_task_set_task_data(task, this, nullptr);57 if (!self->InitPam() || !self->pam_handle_)
5458 {
55 g_task_run_in_thread(task, [] (GTask* task, gpointer, gpointer data, GCancellable*) {59 self->pam_handle_ = nullptr;
56 auto self = static_cast<UserAuthenticatorPam*>(data);60 self->source_manager_.AddTimeout(0, [self] { self->start_failed.emit(); return false; });
5761 return nullptr;
58 self->status_ = pam_authenticate(self->pam_handle_, 0);62 }
5963
60 if (self->status_ == PAM_SUCCESS)64 self->status_ = pam_authenticate(self->pam_handle_, 0);
61 {65
62 int status2 = pam_acct_mgmt(self->pam_handle_, 0);66 if (self->status_ == PAM_SUCCESS)
6367 {
64 if (status2 == PAM_NEW_AUTHTOK_REQD)68 int status2 = pam_acct_mgmt(self->pam_handle_, 0);
65 status2 = pam_chauthtok(self->pam_handle_, PAM_CHANGE_EXPIRED_AUTHTOK);69
6670 if (status2 == PAM_NEW_AUTHTOK_REQD)
67 if (unity::Settings::Instance().pam_check_account_type())71 status2 = pam_chauthtok(self->pam_handle_, PAM_CHANGE_EXPIRED_AUTHTOK);
68 self->status_ = status2;72
6973 if (unity::Settings::Instance().pam_check_account_type())
70 pam_setcred(self->pam_handle_, PAM_REINITIALIZE_CRED);74 self->status_ = status2;
71 }75
72 });76 pam_setcred(self->pam_handle_, PAM_REINITIALIZE_CRED);
7377 }
74 return true;78
79 pam_end(self->pam_handle_, self->status_);
80 self->pam_handle_ = nullptr;
81 self->source_manager_.AddTimeout(0, [self] { self->authenticate_cb_(self->status_ == PAM_SUCCESS); return false; });
82 return nullptr;
75}83}
7684
77bool UserAuthenticatorPam::InitPam()85bool UserAuthenticatorPam::InitPam()
7886
=== modified file 'lockscreen/UserAuthenticatorPam.h'
--- lockscreen/UserAuthenticatorPam.h 2014-03-05 04:09:13 +0000
+++ lockscreen/UserAuthenticatorPam.h 2017-09-15 13:37:27 +0000
@@ -20,8 +20,6 @@
20#ifndef UNITY_USER_AUTHENTICATOR_PAM_H20#ifndef UNITY_USER_AUTHENTICATOR_PAM_H
21#define UNITY_USER_AUTHENTICATOR_PAM_H21#define UNITY_USER_AUTHENTICATOR_PAM_H
2222
23#include <boost/noncopyable.hpp>
24#include <UnityCore/GLibWrapper.h>
25#include <UnityCore/GLibSource.h>23#include <UnityCore/GLibSource.h>
2624
27#include "UserAuthenticator.h"25#include "UserAuthenticator.h"
@@ -36,13 +34,17 @@
36namespace lockscreen34namespace lockscreen
37{35{
3836
39class UserAuthenticatorPam : public UserAuthenticator, private boost::noncopyable37class UserAuthenticatorPam : public UserAuthenticator
40{38{
41public:39public:
40 UserAuthenticatorPam() = default;
42 bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) override;41 bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) override;
4342
44private:43private:
45 // TODO (andy) move to pimpl44 UserAuthenticatorPam(UserAuthenticatorPam const&) = delete;
45 UserAuthenticatorPam& operator=(UserAuthenticatorPam const&) = delete;
46
47 static gpointer AuthenticationThreadFunc(gpointer);
46 bool InitPam();48 bool InitPam();
4749
48 static int ConversationFunction(int num_msg,50 static int ConversationFunction(int num_msg,
@@ -53,10 +55,9 @@
53 std::string username_;55 std::string username_;
54 AuthenticateEndCallback authenticate_cb_;56 AuthenticateEndCallback authenticate_cb_;
5557
56 int status_;58 int status_ = 0;
57 bool first_prompt_;59 bool first_prompt_ = true;
58 pam_handle* pam_handle_;60 pam_handle* pam_handle_ = nullptr;
59 glib::Cancellable cancellable_;
60 glib::SourceManager source_manager_;61 glib::SourceManager source_manager_;
61};62};
6263
6364
=== modified file 'lockscreen/UserPromptView.cpp'
--- lockscreen/UserPromptView.cpp 2016-06-23 14:51:42 +0000
+++ lockscreen/UserPromptView.cpp 2017-09-15 13:37:27 +0000
@@ -23,6 +23,7 @@
23#include <glib/gi18n-lib.h>23#include <glib/gi18n-lib.h>
2424
25#include <boost/algorithm/string/trim.hpp>25#include <boost/algorithm/string/trim.hpp>
26#include <NuxCore/Logger.h>
26#include <Nux/VLayout.h>27#include <Nux/VLayout.h>
2728
28#include "LockScreenSettings.h"29#include "LockScreenSettings.h"
@@ -38,6 +39,9 @@
38{39{
39namespace40namespace
40{41{
42
43DECLARE_LOGGER(logger, "unity.lockscreen");
44
41const RawPixel PADDING = 10_em;45const RawPixel PADDING = 10_em;
42const RawPixel LAYOUT_MARGIN = 10_em;46const RawPixel LAYOUT_MARGIN = 10_em;
43const RawPixel MSG_LAYOUT_MARGIN = 15_em;47const RawPixel MSG_LAYOUT_MARGIN = 15_em;
@@ -101,41 +105,46 @@
101105
102}106}
103107
104UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)108UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager,
105 : AbstractUserPromptView(session_manager)109 UserAuthenticator::Ptr const& user_authenticator)
106 , session_manager_(session_manager)110 : AbstractUserPromptView(session_manager, user_authenticator)
107 , username_(nullptr)111 , username_(nullptr)
108 , msg_layout_(nullptr)112 , msg_layout_(nullptr)
109 , prompt_layout_(nullptr)113 , prompt_layout_(nullptr)
110 , button_layout_(nullptr)114 , button_layout_(nullptr)
111 , prompted_(false)115 , prompted_(false)
112 , unacknowledged_messages_(false)116 , unacknowledged_messages_(false)
117 , num_retry_auth_(0)
113{118{
114 user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){119 user_authenticator_->start_failed.connect(sigc::track_obj([this](){
120 HandleAuthenticationStartFailure();
121 }, *this));
122
123 user_authenticator_->echo_on_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){
115 prompted_ = true;124 prompted_ = true;
116 unacknowledged_messages_ = false;125 unacknowledged_messages_ = false;
117 AddPrompt(message, /* visible */ true, promise);126 AddPrompt(message, /* visible */ true, promise);
118 });127 }, *this));
119128
120 user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){129 user_authenticator_->echo_off_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){
121 prompted_ = true;130 prompted_ = true;
122 unacknowledged_messages_ = false;131 unacknowledged_messages_ = false;
123 AddPrompt(message, /* visible */ false, promise);132 AddPrompt(message, /* visible */ false, promise);
124 });133 }, *this));
125134
126 user_authenticator_.message_requested.connect([this](std::string const& message){135 user_authenticator_->message_requested.connect(sigc::track_obj([this](std::string const& message){
127 unacknowledged_messages_ = true;136 unacknowledged_messages_ = true;
128 AddMessage(message, nux::color::White);137 AddMessage(message, nux::color::White);
129 });138 }, *this));
130139
131 user_authenticator_.error_requested.connect([this](std::string const& message){140 user_authenticator_->error_requested.connect(sigc::track_obj([this](std::string const& message){
132 unacknowledged_messages_ = true;141 unacknowledged_messages_ = true;
133 AddMessage(message, nux::color::Red);142 AddMessage(message, nux::color::Red);
134 });143 }, *this));
135144
136 user_authenticator_.clear_prompts.connect([this](){145 user_authenticator_->clear_prompts.connect(sigc::track_obj([this](){
137 ResetLayout();146 ResetLayout();
138 });147 }, *this));
139148
140 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &UserPromptView::UpdateSize)));149 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &UserPromptView::UpdateSize)));
141150
@@ -469,8 +478,11 @@
469 prompted_ = false;478 prompted_ = false;
470 unacknowledged_messages_ = false;479 unacknowledged_messages_ = false;
471480
472 user_authenticator_.AuthenticateStart(session_manager_->UserName(),481 if(!user_authenticator_->AuthenticateStart(session_manager_->UserName(),
473 sigc::mem_fun(this, &UserPromptView::AuthenticationCb));482 sigc::mem_fun(this, &UserPromptView::AuthenticationCb)))
483 {
484 HandleAuthenticationStartFailure();
485 }
474}486}
475487
476void UserPromptView::DoUnlock()488void UserPromptView::DoUnlock()
@@ -478,5 +490,29 @@
478 session_manager_->unlock_requested.emit();490 session_manager_->unlock_requested.emit();
479}491}
480492
493void UserPromptView::HandleAuthenticationStartFailure()
494{
495 ++num_retry_auth_;
496
497 if (num_retry_auth_ <= 5)
498 {
499 LOG_WARNING(logger) << "Failed to start the authentication process. Retrying for " << num_retry_auth_ << " time.";
500 source_manager_.AddTimeout(100, [this] {
501 StartAuthentication();
502 return false;
503 });
504 }
505 else
506 {
507 num_retry_auth_ = 0;
508
509 AddMessage(_("Authentication failure"), nux::color::Red);
510 AddButton(_("Switch to greeter…"), [this] {
511 session_manager_->SwitchToGreeter();
512 });
513 GetLayout()->AddLayout(button_layout_);
514 }
515}
516
481}517}
482}518}
483519
=== modified file 'lockscreen/UserPromptView.h'
--- lockscreen/UserPromptView.h 2016-06-23 14:51:42 +0000
+++ lockscreen/UserPromptView.h 2017-09-15 13:37:27 +0000
@@ -25,10 +25,10 @@
2525
26#include <Nux/Nux.h>26#include <Nux/Nux.h>
27#include <Nux/View.h>27#include <Nux/View.h>
28#include "UnityCore/GLibSource.h"
28#include "UnityCore/SessionManager.h"29#include "UnityCore/SessionManager.h"
2930
30#include "LockScreenAbstractPromptView.h"31#include "LockScreenAbstractPromptView.h"
31#include "UserAuthenticatorPam.h"
32#include "unity-shared/IMTextEntry.h"32#include "unity-shared/IMTextEntry.h"
3333
34namespace nux34namespace nux
@@ -48,7 +48,8 @@
48class UserPromptView : public AbstractUserPromptView48class UserPromptView : public AbstractUserPromptView
49{49{
50public:50public:
51 UserPromptView(session::Manager::Ptr const& session_manager);51 UserPromptView(session::Manager::Ptr const& session_manager,
52 UserAuthenticator::Ptr const& user_authenticator);
5253
53 nux::View* focus_view();54 nux::View* focus_view();
5455
@@ -70,9 +71,8 @@
70 void ShowAuthenticated(bool successful);71 void ShowAuthenticated(bool successful);
71 void StartAuthentication();72 void StartAuthentication();
72 void DoUnlock();73 void DoUnlock();
74 void HandleAuthenticationStartFailure();
7375
74 session::Manager::Ptr session_manager_;
75 UserAuthenticatorPam user_authenticator_;
76 std::shared_ptr<nux::AbstractPaintLayer> bg_layer_;76 std::shared_ptr<nux::AbstractPaintLayer> bg_layer_;
77 StaticCairoText* username_;77 StaticCairoText* username_;
78 nux::VLayout* msg_layout_;78 nux::VLayout* msg_layout_;
@@ -84,6 +84,9 @@
8484
85 bool prompted_;85 bool prompted_;
86 bool unacknowledged_messages_;86 bool unacknowledged_messages_;
87 int num_retry_auth_ = 0;
88
89 glib::SourceManager source_manager_;
87};90};
8891
89}92}