Skip to content
Snippets Groups Projects
Commit 6495de89 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

account: register username

Ask for password when register username.

Change-Id: I898f616a9f7c6a3596c3eb1384cdee79d8a65339
parent c8c7abc6
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,10 @@
*/
@property (assign)BOOL isUserNameAvailable;
@property (assign)BOOL couldRegister;
@property (assign)NSString* passwordString;
@property std::string selectedAccountID;
@end
......@@ -30,6 +30,9 @@
@implementation RegisterNameWC
{
__unsafe_unretained IBOutlet NSTextField* registeredNameField;
__unsafe_unretained IBOutlet NSSecureTextField* passwordField;
__unsafe_unretained IBOutlet NSTextField* passwordLabel;
__unsafe_unretained IBOutlet NSLayoutConstraint* passwordTopConstraint;
__unsafe_unretained IBOutlet NSImageView* ivLookupResult;
__unsafe_unretained IBOutlet NSProgressIndicator* indicatorLookupResult;
......@@ -39,10 +42,12 @@
QMetaObject::Connection registeredNameFound;
BOOL lookupQueued;
BOOL needPassword;
NSString* usernameWaitingForLookupResult;
}
NSInteger const BLOCKCHAIN_NAME_TAG = 2;
NSInteger const PASSWORD_TAG = 3;
@synthesize accountModel;
......@@ -59,6 +64,11 @@ NSInteger const BLOCKCHAIN_NAME_TAG = 2;
{
[super windowDidLoad];
auto accounts = self.accountModel->getAccountList();
lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
needPassword = accountProperties.archiveHasPassword;
[passwordField setHidden: !needPassword];
[passwordLabel setHidden: !needPassword];
passwordTopConstraint.constant = needPassword ? 20.0 : -20.0;
[registeredNameField setTag:BLOCKCHAIN_NAME_TAG];
[ivLookupResult setHidden:YES];
[indicatorLookupResult setHidden:YES];
......@@ -81,6 +91,10 @@ NSInteger const BLOCKCHAIN_NAME_TAG = 2;
- (void)onUsernameAvailabilityChangedWithNewAvailability:(BOOL)newAvailability
{
self.isUserNameAvailable = newAvailability;
self.couldRegister = needPassword ?
self.isUserNameAvailable && [self.passwordString length] > 0 :
self.isUserNameAvailable;
}
- (void)hideLookupSpinner
......@@ -162,15 +176,18 @@ NSInteger const BLOCKCHAIN_NAME_TAG = 2;
- (void)controlTextDidChange:(NSNotification *)notif
{
NSTextField* textField = [notif object];
if (textField.tag != BLOCKCHAIN_NAME_TAG) {
return;
if (textField.tag == BLOCKCHAIN_NAME_TAG) {
NSString* alias = textField.stringValue;
[self showLookupSpinner];
[self onUsernameAvailabilityChangedWithNewAvailability:NO];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(lookUp:) withObject:alias afterDelay:0.5];
} else if (textField.tag == PASSWORD_TAG) {
self.couldRegister = needPassword ?
self.isUserNameAvailable && [self.passwordString length] > 0 :
self.isUserNameAvailable;
}
NSString* alias = textField.stringValue;
[self showLookupSpinner];
[self onUsernameAvailabilityChangedWithNewAvailability:NO];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(lookUp:) withObject:alias afterDelay:0.5];
}
- (void) lookUp:(NSString*) name
......@@ -186,11 +203,17 @@ NSInteger const BLOCKCHAIN_NAME_TAG = 2;
- (IBAction)registerUsername:(id)sender
{
NSString *password = passwordField.stringValue;
if((!password || [password length] == 0) && needPassword) {
return;
}
[registrationProgress startAnimation:nil];
[self showLoading];
[self setCallback];
self.isUserNameAvailable = self.accountModel->registerName(self.selectedAccountID, "", [registeredNameField.stringValue UTF8String]);
self.isUserNameAvailable = self.accountModel->registerName(self.selectedAccountID,
[password UTF8String],
[registeredNameField.stringValue UTF8String]);
if (!self.isUserNameAvailable) {
NSLog(@"Could not initialize registerName operation");
QObject::disconnect(registrationEnded);
......
......@@ -11,6 +11,9 @@
<outlet property="indicatorLookupResult" destination="Osd-Vq-u7C" id="Adn-ta-XTG"/>
<outlet property="initialContainer" destination="gKX-gX-nko" id="tjc-HW-KBM"/>
<outlet property="ivLookupResult" destination="kfj-jZ-xal" id="w7y-8W-MWT"/>
<outlet property="passwordField" destination="xQP-ub-HYB" id="9Fp-Yp-88o"/>
<outlet property="passwordLabel" destination="XfC-gt-lOT" id="s22-ds-Fwb"/>
<outlet property="passwordTopConstraint" destination="lhL-HJ-4sQ" id="cOB-JT-Har"/>
<outlet property="progressContainer" destination="WWd-Hs-Pwi" id="YK7-bp-wp7"/>
<outlet property="registeredNameField" destination="LVv-bg-Ols" id="2Cc-TI-koh"/>
<outlet property="registrationProgress" destination="1rt-CR-Wpz" id="djT-M6-eei"/>
......@@ -25,14 +28,14 @@
<rect key="contentRect" x="131" y="165" width="410" height="213"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<view key="contentView" id="fhx-qk-94n">
<rect key="frame" x="0.0" y="0.0" width="410" height="162"/>
<rect key="frame" x="0.0" y="0.0" width="410" height="199"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="szF-XD-rRG">
<rect key="frame" x="0.0" y="0.0" width="410" height="162"/>
<rect key="frame" x="0.0" y="0.0" width="410" height="199"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YAP-cJ-hMx">
<rect key="frame" x="33" y="73" width="344" height="17"/>
<rect key="frame" x="33" y="91" width="344" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="340" id="2Gn-1g-YtT"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="340" id="lK4-ZA-NTA"/>
......@@ -65,10 +68,10 @@ DQ
</constraints>
</customView>
<view translatesAutoresizingMaskIntoConstraints="NO" id="gKX-gX-nko">
<rect key="frame" x="0.0" y="0.0" width="410" height="162"/>
<rect key="frame" x="0.0" y="0.0" width="410" height="199"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3cW-Kr-1oI">
<rect key="frame" x="33" y="125" width="359" height="17"/>
<rect key="frame" x="33" y="162" width="359" height="17"/>
<textFieldCell key="cell" controlSize="mini" sendsActionOnEndEditing="YES" alignment="left" title="Register a public username " id="tje-EZ-ZPI">
<font key="font" metaFont="systemSemibold" size="13"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
......@@ -76,7 +79,7 @@ DQ
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oFy-jN-crC">
<rect key="frame" x="33" y="103" width="359" height="17"/>
<rect key="frame" x="33" y="140" width="359" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Other users can use it instead of your ID" id="9gi-0u-67t">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
......@@ -84,7 +87,7 @@ DQ
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LVv-bg-Ols">
<rect key="frame" x="136" y="66" width="200" height="22"/>
<rect key="frame" x="136" y="103" width="200" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="tbX-cT-w6C"/>
</constraints>
......@@ -98,13 +101,44 @@ DQ
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pyd-lM-kiF">
<rect key="frame" x="65" y="69" width="66" height="17"/>
<rect key="frame" x="65" y="106" width="66" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Username" id="lo5-ei-wHM">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XfC-gt-lOT">
<rect key="frame" x="65" y="69" width="66" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Password" id="egF-LJ-khJ">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" tag="3" translatesAutoresizingMaskIntoConstraints="NO" id="xQP-ub-HYB" customClass="NSSecureTextField">
<rect key="frame" x="136" y="66" width="200" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="d5S-WB-eLW"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="Enter password..." bezelStyle="round" id="nFA-uz-WjI">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="-2" name="value" keyPath="self.passwordString" id="JkL-9W-ex1">
<dictionary key="options">
<bool key="NSContinuouslyUpdatesValue" value="YES"/>
<string key="NSMultipleValuesPlaceholder">Enter password...</string>
<string key="NSNoSelectionPlaceholder">Enter password...</string>
<string key="NSNotApplicablePlaceholder">Enter password...</string>
<string key="NSNullPlaceholder">Enter password...</string>
</dictionary>
</binding>
<outlet property="delegate" destination="-2" id="DWN-Ji-eN4"/>
</connections>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GhT-2W-DrB">
<rect key="frame" x="224" y="13" width="82" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="eoS-s7-b3w">
......@@ -129,11 +163,11 @@ DQ
</buttonCell>
<connections>
<action selector="registerUsername:" target="-2" id="zAU-Ve-eYp"/>
<binding destination="-2" name="enabled" keyPath="self.isUserNameAvailable" id="DJ0-jU-oIl"/>
<binding destination="-2" name="enabled" keyPath="self.couldRegister" id="dNp-nr-QTp"/>
</connections>
</button>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="JGA-h8-Nhd">
<rect key="frame" x="343" y="67" width="20" height="20"/>
<rect key="frame" x="343" y="104" width="20" height="20"/>
<subviews>
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="Osd-Vq-u7C">
<rect key="frame" x="0.0" y="0.0" width="20" height="20"/>
......@@ -163,26 +197,33 @@ DQ
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="3cW-Kr-1oI" secondAttribute="trailing" constant="20" id="29P-ZA-iM6"/>
<constraint firstItem="LVv-bg-Ols" firstAttribute="trailing" secondItem="xQP-ub-HYB" secondAttribute="trailing" id="4Xe-4F-LPU"/>
<constraint firstItem="LVv-bg-Ols" firstAttribute="leading" secondItem="xQP-ub-HYB" secondAttribute="leading" id="AKN-1U-mOY"/>
<constraint firstAttribute="bottom" secondItem="GhT-2W-DrB" secondAttribute="bottom" constant="20" id="Fkg-bx-DFy"/>
<constraint firstItem="kxj-la-grj" firstAttribute="top" secondItem="xQP-ub-HYB" secondAttribute="bottom" constant="25" id="Gex-MP-0Ha"/>
<constraint firstItem="LVv-bg-Ols" firstAttribute="top" secondItem="oFy-jN-crC" secondAttribute="bottom" constant="15" id="I29-cu-eYL"/>
<constraint firstItem="3cW-Kr-1oI" firstAttribute="top" secondItem="gKX-gX-nko" secondAttribute="top" constant="20" id="Idb-Wu-QEH"/>
<constraint firstItem="LVv-bg-Ols" firstAttribute="leading" secondItem="pyd-lM-kiF" secondAttribute="trailing" constant="7" id="MKN-id-BgO"/>
<constraint firstItem="oFy-jN-crC" firstAttribute="top" secondItem="3cW-Kr-1oI" secondAttribute="bottom" constant="5" id="McA-nZ-5z9"/>
<constraint firstItem="JGA-h8-Nhd" firstAttribute="leading" secondItem="LVv-bg-Ols" secondAttribute="trailing" constant="7" id="SIK-Kb-6ET"/>
<constraint firstItem="XfC-gt-lOT" firstAttribute="leading" secondItem="pyd-lM-kiF" secondAttribute="leading" id="SsJ-os-kMi"/>
<constraint firstAttribute="trailing" secondItem="kxj-la-grj" secondAttribute="trailing" constant="20" id="WS6-w2-SOa"/>
<constraint firstItem="XfC-gt-lOT" firstAttribute="trailing" secondItem="pyd-lM-kiF" secondAttribute="trailing" id="WlN-OU-mKH"/>
<constraint firstItem="oFy-jN-crC" firstAttribute="leading" secondItem="gKX-gX-nko" secondAttribute="leading" constant="35" id="X0d-vt-KnX"/>
<constraint firstItem="xQP-ub-HYB" firstAttribute="centerY" secondItem="XfC-gt-lOT" secondAttribute="centerY" id="YT6-mU-uO3"/>
<constraint firstItem="kxj-la-grj" firstAttribute="leading" secondItem="GhT-2W-DrB" secondAttribute="trailing" constant="12" id="bwP-n4-ByA"/>
<constraint firstAttribute="trailing" secondItem="oFy-jN-crC" secondAttribute="trailing" constant="20" id="fBK-4g-wxS"/>
<constraint firstItem="pyd-lM-kiF" firstAttribute="centerY" secondItem="LVv-bg-Ols" secondAttribute="centerY" id="gBZ-EX-YEN"/>
<constraint firstItem="JGA-h8-Nhd" firstAttribute="centerY" secondItem="LVv-bg-Ols" secondAttribute="centerY" id="k40-hp-KCp"/>
<constraint firstItem="XfC-gt-lOT" firstAttribute="top" secondItem="pyd-lM-kiF" secondAttribute="bottom" constant="20" id="lhL-HJ-4sQ"/>
<constraint firstItem="pyd-lM-kiF" firstAttribute="leading" secondItem="oFy-jN-crC" secondAttribute="leading" constant="32" id="tVF-hj-BRq"/>
<constraint firstItem="kxj-la-grj" firstAttribute="top" secondItem="LVv-bg-Ols" secondAttribute="bottom" constant="25" id="uO8-vt-bRv"/>
<constraint firstAttribute="bottom" secondItem="kxj-la-grj" secondAttribute="bottom" constant="20" id="w0D-Vo-Z48"/>
<constraint firstItem="3cW-Kr-1oI" firstAttribute="leading" secondItem="gKX-gX-nko" secondAttribute="leading" constant="35" id="y5J-9x-SsV"/>
<constraint firstItem="kxj-la-grj" firstAttribute="centerY" secondItem="GhT-2W-DrB" secondAttribute="centerY" id="yOe-uY-OmX"/>
</constraints>
</view>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="WWd-Hs-Pwi">
<rect key="frame" x="0.0" y="0.0" width="410" height="162"/>
<rect key="frame" x="0.0" y="19" width="410" height="162"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1hK-Hw-cJh">
<rect key="frame" x="151" y="66" width="109" height="17"/>
......@@ -244,6 +285,7 @@ Gw
</connections>
<point key="canvasLocation" x="-446" y="439.5"/>
</window>
<userDefaultsController representsSharedInstance="YES" id="0af-ZE-2wb"/>
</objects>
<resources>
<image name="ic_action_accept" width="72" height="72"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment