Ind.ie is now Small Technology Foundation.
Commit bfb07a3c authored by Aral Balkan's avatar Aral Balkan

Waystone now validates invitation codes and we are handling Waystone account...

Waystone now validates invitation codes and we are handling Waystone account setup failures more gracefully. Closes #115.
parent 96de6b4e
......@@ -31,6 +31,9 @@ class SetupStepTwoViewController: SetupStepViewController
@IBOutlet weak var profileImagePickerTopSpaceToContainerConstraint: NSLayoutConstraint!
@IBOutlet weak var nameTextFieldTopSpaceToProfileImagePickerComponentConstraint: NSLayoutConstraint!
var profileImagePickerTopSpaceToContainerConstraintOriginalConstant: CGFloat!
var nameTextFieldTopSpaceToProfileImagePickerComponentConstraintOriginalConstant: CGFloat!
// Embedded via segue
var profileImageComponent:ProfileImageComponentViewController!
......@@ -59,6 +62,43 @@ class SetupStepTwoViewController: SetupStepViewController
// TODO: ^^^ Move these to the handlers also and persist immediately.
}
override func prepareForDisplayViaBackButton()
{
println("ℹ️ Returning to Step Two of the Setup process. (\(self))\n")
//
// Animate the view back to its editing orientation.
// TODO: Refactor to remove redundancies with animateFormWhenDoneEditing
//
// Mark the Profile Image Component as not editable
// (This will gracefully remove its controls).
profileImageComponent.editable = true
// // This is a workaround to a visual glitch that otherwise draws boxes around the components.
// self.personNameTextField.drawsBackground = true
// self.personNameTextField.backgroundColor = NSColor(calibratedWhite: 100.0, alpha: 0.0)
// self.bioTextField.drawsBackground = true
// self.bioTextField.backgroundColor = NSColor(calibratedWhite: 100.0, alpha: 0.0)
//
// End animation values for the constraints.
self.profileImagePickerTopSpaceToContainerConstraint.constant = self.profileImagePickerTopSpaceToContainerConstraintOriginalConstant
self.nameTextFieldTopSpaceToProfileImagePickerComponentConstraint.constant = self.nameTextFieldTopSpaceToProfileImagePickerComponentConstraintOriginalConstant
NSAnimationContext.runAnimationGroup(
{
(context:NSAnimationContext!) -> Void in
context.duration = 0.89
context.allowsImplicitAnimation = true
self.view.layoutSubtreeIfNeeded()
},
completionHandler:
{
() -> Void in
println("View back to normal.")
})
}
//
// Handle visual feedback once person has indicated that they’re done editing the form.
......@@ -74,6 +114,11 @@ class SetupStepTwoViewController: SetupStepViewController
self.personNameTextField.backgroundColor = NSColor(calibratedWhite: 100.0, alpha: 0.0)
self.bioTextField.drawsBackground = true
self.bioTextField.backgroundColor = NSColor(calibratedWhite: 100.0, alpha: 0.0)
// Save the current constraint constants so we can revert the form back
// if we need to (i.e., if there’s an error while creating the account).
self.profileImagePickerTopSpaceToContainerConstraintOriginalConstant = self.profileImagePickerTopSpaceToContainerConstraint.constant
self.nameTextFieldTopSpaceToProfileImagePickerComponentConstraintOriginalConstant = self.nameTextFieldTopSpaceToProfileImagePickerComponentConstraint.constant
// End animation values for the constraints.
self.profileImagePickerTopSpaceToContainerConstraint.constant = 100.0
......
......@@ -304,15 +304,49 @@ class SetupViewController: NSViewController, SetupDelegate
println(SetupData)
// Get the account handle safely.
Node.sharedInstance.call(remoteFunction.named(remoteFunction.initialiseHeartbeatWithWaystoneAccount), withArguments: [SetupData.accountHandle!])
Node.sharedInstance.call(remoteFunction.named(remoteFunction.initialiseHeartbeatWithWaystoneAccount), withArguments: [SetupData.accountHandle!, SetupData.invitationCode!])
{
/* and handle */ response in
println("ℹ️ Call to initialise Heartbeat with Waystone Account returned from Node.\n")
// TODO: Check if response is successful before trying to save local data.
println(response)
if response["error"].boolValue
{
// Response was not successful, let the person know.
let errorMessage = response["errorMessage"].stringValue
let prettyErrorMessage = "Error \(errorMessage)"
println("❌ Response was not successful. \(prettyErrorMessage)")
// Stop the progress indicator.
self.hideProgress()
let errorSheet = NSAlert()
errorSheet.messageText = "Sorry, could not set up your account on Ind.ie."
errorSheet.informativeText = prettyErrorMessage
errorSheet.alertStyle = NSAlertStyle.CriticalAlertStyle
errorSheet.addButtonWithTitle("OK")
errorSheet.beginSheetModalForWindow(self.view.window!)
{
/* and handle */ response in
self.prepareInterfaceForChangeToStep(2)
// Signal to the SetupStepTwoViewController that we are going back to it.
let currentViewController:SetupStepViewController = self.viewControllers[self.currentStep-1]
currentViewController.prepareForDisplayViaBackButton()
}
return
}
//
// Response was successful, continue with local setup.
//
// !!!!! ASSUMING IT’S SUCCESSFUL FOR NOW. !!!!!
SetupData.deviceID = response["deviceID"].stringValue
//
......@@ -483,8 +517,6 @@ class SetupViewController: NSViewController, SetupDelegate
{
//
// OK, the invitation code is correct, it’s safe to proceed with account creation.
// TODO: Get the invitation code in the notification and pass it onto Waystone
// ===== so it can perform server-side validation on the invitation code.
//
if let userInfo = notification.userInfo
......
false
\ No newline at end of file
true
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment