diff --git a/interface/resources/images/hifi-logo.png b/interface/resources/images/hifi-logo.png new file mode 100644 index 0000000000..dde423ff8b Binary files /dev/null and b/interface/resources/images/hifi-logo.png differ diff --git a/interface/resources/images/login.svg b/interface/resources/images/login.svg new file mode 100644 index 0000000000..1a5b254055 --- /dev/null +++ b/interface/resources/images/login.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp new file mode 100644 index 0000000000..67c99ad53d --- /dev/null +++ b/interface/src/ui/LoginDialog.cpp @@ -0,0 +1,98 @@ +// +// LoginDialog.cpp +// interface/src/ui +// +// Created by Ryan Huffman on 4/23/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include +#include +#include + +#include "Application.h" +#include "Menu.h" +#include "AccountManager.h" +#include "ui_loginDialog.h" + +#include "LoginDialog.h" + +const QString FORGOT_PASSWORD_URL = "http://highfidelity.io"; + +LoginDialog::LoginDialog(QWidget* parent) : + FramelessDialog(parent, 0, FramelessDialog::POSITION_TOP), + _ui(new Ui::LoginDialog) { + + _ui->setupUi(this); + _ui->errorLabel->hide(); + _ui->emailLineEdit->setFocus(); + _ui->logoLabel->setPixmap(QPixmap(Application::resourcesPath() + "images/hifi-logo.png")); + _ui->loginButton->setIcon(QIcon(Application::resourcesPath() + "images/login.svg")); + _ui->infoLabel->setVisible(false); + _ui->errorLabel->setVisible(false); + + setModal(true); + setHideOnBlur(false); + + connect(&AccountManager::getInstance(), &AccountManager::loginComplete, + this, &LoginDialog::handleLoginCompleted); + connect(&AccountManager::getInstance(), &AccountManager::loginFailed, + this, &LoginDialog::handleLoginFailed); + connect(_ui->loginButton, &QPushButton::clicked, + this, &LoginDialog::handleLoginClicked); + connect(_ui->closeButton, &QPushButton::clicked, + this, &LoginDialog::close); + connect(_ui->forgotPasswordButton, &QPushButton::clicked, + this, &LoginDialog::handleForgotPasswordClicked); +}; + +LoginDialog::~LoginDialog() { + delete _ui; +}; + +void LoginDialog::handleLoginCompleted(const QUrl& authURL) { + _ui->infoLabel->setVisible(false); + _ui->errorLabel->setVisible(false); + close(); +}; + +void LoginDialog::handleLoginFailed() { + _ui->errorLabel->setText("Login Failure: Invalid username or password"); + + _ui->infoLabel->setVisible(false); + _ui->errorLabel->setVisible(true); + + _ui->errorLabel->show(); + _ui->loginAreaContainer->setDisabled(false); + _ui->emailLineEdit->setFocus(); + _ui->emailLineEdit->setSelection(0, _ui->emailLineEdit->maxLength()); +}; + +void LoginDialog::handleLoginClicked() { + // If the email or password inputs are empty, move focus to them, otherwise attempt to login. + if (_ui->emailLineEdit->text().isEmpty()) { + _ui->emailLineEdit->setFocus(); + } else if (_ui->passwordLineEdit->text().isEmpty()) { + _ui->passwordLineEdit->setFocus(); + } else { + _ui->infoLabel->setText("Authenticating..."); + _ui->infoLabel->setVisible(true); + _ui->errorLabel->setVisible(false); + + _ui->loginAreaContainer->setDisabled(true); + AccountManager::getInstance().requestAccessToken(_ui->emailLineEdit->text(), _ui->passwordLineEdit->text()); + } +}; + +void LoginDialog::handleForgotPasswordClicked() { + Menu::getInstance()->openUrl(FORGOT_PASSWORD_URL); +}; + +void LoginDialog::moveEvent(QMoveEvent* event) { + // Modal dialogs seemed to get repositioned automatically. Combat this by moving the window if needed. + resizeAndPosition(); +}; diff --git a/interface/src/ui/LoginDialog.h b/interface/src/ui/LoginDialog.h new file mode 100644 index 0000000000..91634559ee --- /dev/null +++ b/interface/src/ui/LoginDialog.h @@ -0,0 +1,43 @@ +// +// LoginDialog.h +// interface/src/ui +// +// Created by Ryan Huffman on 4/23/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_LoginDialog_h +#define hifi_LoginDialog_h + +#include +#include "FramelessDialog.h" + +namespace Ui { + class LoginDialog; +} + +class LoginDialog : public FramelessDialog { + Q_OBJECT + +public: + LoginDialog(QWidget* parent); + ~LoginDialog(); + +public slots: + void handleLoginClicked(); + void handleForgotPasswordClicked(); + void handleLoginCompleted(const QUrl& authURL); + void handleLoginFailed(); + +protected: + void moveEvent(QMoveEvent* event); + +private: + Ui::LoginDialog* _ui; + +}; + +#endif // hifi_LoginDialog_h diff --git a/interface/ui/loginDialog.ui b/interface/ui/loginDialog.ui new file mode 100644 index 0000000000..2764815c1e --- /dev/null +++ b/interface/ui/loginDialog.ui @@ -0,0 +1,410 @@ + + + LoginDialog + + + + 0 + 0 + 1159 + 130 + + + + + 0 + 130 + + + + Dialog + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 30 + + + + + 5 + + + 0 + + + 6 + + + 10 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 18 + + + + Message + + + + + + + true + + + + 18 + + + + color: red + + + Error + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 16 + 16 + + + + + 16 + 16 + + + + SplitHCursor + + + + + + + + + + ../resources/images/close.svg../resources/images/close.svg + + + true + + + + + + + + + + true + + + + 0 + 0 + + + + + 0 + 102 + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 30 + + + + + + 0 + 0 + + + + + 931 + 60 + + + + QLineEdit { + padding: 10px; +border-width: 1px; border-style: solid; border-radius: 3px; border-color: #aaa; +} + + + + 12 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + ../resources/images/hifi-logo.png + + + + + + + + 0 + 0 + + + + + 300 + 54 + + + + + 20 + + + + + + + + + + Username or Email + + + + + + + + 0 + 0 + + + + + 300 + 54 + + + + + 20 + + + + + + + + + + QLineEdit::Password + + + Password + + + + + + + + 0 + 0 + + + + + 141 + 54 + + + + + 20 + + + + PointingHandCursor + + + +background: #0e7077; +color: #fff; +border-radius: 4px; + + + Login + + + + ../resources/images/login.svg../resources/images/login.svg + + + + 32 + 32 + + + + true + + + true + + + + + + + + 0 + 0 + + + + + 141 + 26 + + + + + 15 + + + + PointingHandCursor + + + color: #0e7077; +background: rgba(0, 0, 0, 0); +border-radius: 4px; + + + Recover Password? + + + false + + + true + + + + + + + + + + + + + +