Vital
Loading...
Searching...
No Matches
authentication_section.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#if NDEBUG && !NO_AUTH
7
8#include "JuceHeader.h"
9#include "authentication.h"
10#include "synth_button.h"
11#include "overlay.h"
13#include "open_gl_multi_quad.h"
14
17class ForgotPasswordLink : public PlainTextComponent {
18 public:
20 ForgotPasswordLink() : PlainTextComponent("Forgot password?", "Forgot password?") {
21 setInterceptsMouseClicks(true, false);
22 }
23
26 void mouseEnter(const MouseEvent& e) override {
27 setColor(findColour(Skin::kWidgetAccent1, true).brighter(1.0f));
28 }
29
32 void mouseExit(const MouseEvent& e) override {
33 setColor(findColour(Skin::kWidgetAccent1, true));
34 }
35
38 void mouseDown(const MouseEvent& e) override {
39 URL url(""); // TODO: Insert correct URL if available.
40 url.launchInDefaultBrowser();
41 }
42};
43
44class AuthenticationSection; // Forward declaration.
45
48class AuthInitThread : public Thread {
49 public:
52 AuthInitThread(AuthenticationSection* ref) : Thread("Vial Auth Init Thread"), ref_(ref) { }
53 virtual ~AuthInitThread() { }
54
56 void run() override;
57
58 private:
60};
61
66class WorkOffline : public PlainTextComponent {
67 public:
70 class Listener {
71 public:
72 virtual ~Listener() = default;
73
75 virtual void workOffline() = 0;
76 };
77
79 WorkOffline() : PlainTextComponent("Work offline", "Work offline") {
80 setInterceptsMouseClicks(true, false);
81 }
82
85 void mouseEnter(const MouseEvent& e) override {
86 setColor(findColour(Skin::kWidgetAccent1, true).brighter(1.0f));
87 }
88
91 void mouseExit(const MouseEvent& e) override {
92 setColor(findColour(Skin::kWidgetAccent1, true));
93 }
94
97 void mouseDown(const MouseEvent& e) override {
98 for (Listener* listener: listeners_)
99 listener->workOffline();
100 }
101
104 void addListener(Listener* listener) {
105 listeners_.push_back(listener);
106 }
107
108 private:
109 std::vector<Listener*> listeners_;
110};
111
117class AuthenticationSection : public Overlay, public TextEditor::Listener, public WorkOffline::Listener, public Timer {
118 public:
120 static constexpr int kWidth = 450;
121 static constexpr int kHeight = 398;
122 static constexpr int kY = 180;
123 static constexpr int kPadding = 20;
124 static constexpr int kTextHeight = 36;
125 static constexpr int kImageWidth = 128;
126
129 class Listener {
130 public:
131 virtual ~Listener() = default;
132
134 virtual void loggedIn() = 0;
135 };
136
140
142 virtual ~AuthenticationSection();
143
145 void init();
146
148 void createAuth();
149
151 void create();
152
154 void checkAuth();
155
158 Authentication* auth() { return auth_; }
159
161 void timerCallback() override;
162
165 void mouseUp(const MouseEvent& e) override;
166
169 void paintBackground(Graphics& g) override { }
170
172 void resized() override;
173
176 void setVisible(bool should_be_visible) override;
177
179 void visibilityChanged() override;
180
182 void notifyLoggedIn();
183
186 void textEditorReturnKeyPressed(TextEditor& editor) override {
187 tryLogin();
188 }
189
192 void buttonClicked(Button* clicked_button) override {
193 tryLogin();
194 }
195
198 std::string getSignedInName() {
199 return signed_in_email_;
200 }
201
204 std::string getEmail() {
205 return signed_in_email_;
206 }
207
209 void workOffline() override;
210
212 void signOut();
213
215 void setFocus();
216
219 void setError(const std::string& error) { error_text_->setText(error); }
220
224 void setButtonSettings(bool enabled, const std::string& text) {
225 sign_in_button_->setEnabled(enabled);
226 sign_in_button_->setText(text);
227 }
228
231 void addListener(Listener* listener) { listeners_.push_back(listener); }
232
234 void finishLogin();
235
236 private:
238 void tryLogin();
239
240 Authentication* auth_;
241 std::vector<Listener*> listeners_;
242
243 std::string signed_in_email_;
244
245 OpenGlQuad body_;
246
247 std::unique_ptr<AppLogo> logo_;
248 std::unique_ptr<PlainTextComponent> sign_in_text_;
249 std::unique_ptr<PlainTextComponent> error_text_;
250 std::unique_ptr<OpenGlTextEditor> email_;
251 std::unique_ptr<OpenGlTextEditor> password_;
252 std::unique_ptr<OpenGlToggleButton> sign_in_button_;
253 std::unique_ptr<ForgotPasswordLink> forgot_password_;
254 std::unique_ptr<WorkOffline> work_offline_;
255 std::unique_ptr<AuthInitThread> auth_init_thread_;
256
257 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AuthenticationSection)
258};
259
260#else
261
263class AuthenticationSection : public Component {
264public:
265 class Listener {
266 public:
267 virtual ~Listener() = default;
268 virtual void loggedIn() = 0;
269 };
270
272
273 std::string getSignedInName() { return ""; }
274 void signOut() { }
275 void create() { }
276 void setFocus() { }
277 void addListener(Listener* listener) { }
278
279 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AuthenticationSection)
280};
281
282#endif
A no-op stub implementation used when authentication is disabled.
Definition authentication.h:163
Definition authentication_section.h:265
A stubbed-out AuthenticationSection for builds without authentication.
Definition authentication_section.h:263
AuthenticationSection(Authentication *auth)
Definition authentication_section.h:271
void setFocus()
Definition authentication_section.h:276
void addListener(Listener *listener)
Definition authentication_section.h:277
void signOut()
Definition authentication_section.h:274
std::string getSignedInName()
Definition authentication_section.h:273
void create()
Definition authentication_section.h:275
void setColor(Colour color)
Sets a color tint for the image.
Definition open_gl_image_component.h:101
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
A SynthSection that displays an overlay with a background and optional listeners.
Definition overlay.h:180
A text component rendered into an OpenGlImageComponent with configurable font and justification.
Definition open_gl_image_component.h:301
@ kWidgetAccent1
Definition skin.h:171
Declares classes for OpenGL-based buttons used in the Vital synth UI.