Exemplo n.º 1
0
        async public override void ViewWillAppear(bool animated)
        {
            showLoading();
            mACM = new AccountManager();
            iOSLoginManager loginManager = iOSLoginManager.Instance;

            mUsername = loginManager.GetUsername();

            mTraveler = await mACM.GetTravelerByEmail(mUsername);

            if (!String.IsNullOrEmpty(mTraveler.PromoCode))
            {
                txtPromoCode.Text      = mTraveler.PromoCode;
                btnSetPromoCode.Hidden = true;
            }
            else
            {
                btnSetPromoCode.Hidden = false;
            }

            lblUsername.Text = mUsername;

                        #if DEBUG
            string versionTag = " debug";
                        #else
            string versionTag = "";
                        #endif
            lblVersion.Text = NSBundle.MainBundle.InfoDictionary [new NSString("CFBundleVersion")].ToString() + versionTag;
            dismissLoading();
        }
Exemplo n.º 2
0
        public TravelerModel UpdateTraveler(TravelerModel traveler)
        {
            TravelerModel travelerResult = new TravelerModel();
            var           client         = new RestClient(BaseUrl);

            client.Authenticator = new HttpBasicAuthenticator(HttpAuthUsername, HttpAuthPassword);

            var request = new RestRequest("Traveler", Method.PUT);

            request.RequestFormat = DataFormat.Json;

            request.AddParameter("id", traveler.Id, ParameterType.QueryString);
            request.AddBody(traveler);

            IRestResponse <TravelerModel> response = client.Execute <TravelerModel>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                throw new Exception("Invalid Promo Code");
            }

            travelerResult = response.Data;

            return(travelerResult);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Manage(AccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                TravelerModel traveler = await loginManager.GetTravelerByEmail(model.accountInfoModel.Email);

                traveler.PromoCode = model.accountInfoModel.PromoCode;

                model.accountInfoModel.PromoCodeUpdated = true;
                try
                {
                    TravelerModel updatedTraveler = loginManager.UpdateTraveler(traveler);
                    if (updatedTraveler.Email == model.accountInfoModel.Email)
                    {
                        ModelState.AddModelError("accountInfoModel", "Settings Updated");
                        model.accountInfoModel.PromoCodeValid = true;
                    }
                    else
                    {
                        ModelState.AddModelError("accountInfoModel", "Update Failed");
                        model.accountInfoModel.PromoCodeValid = false;
                        model.accountInfoModel.PromoCode      = null;
                    }
                }catch (Exception ex)
                {
                    model.accountInfoModel.PromoCodeValid = false;
                    model.accountInfoModel.PromoCode      = null;
                }
            }

            return(View(model));
        }
Exemplo n.º 4
0
        public void TermsDismissed(bool isAccepted)
        {
            this.DismissViewController(true, async() => {
                if (!isAccepted)
                {
                    NavigationController.PopViewControllerAnimated(true);
                }
                else
                {
                    AccountManager acm = new AccountManager();

                    iOSLoginManager loginManager = iOSLoginManager.Instance;

                    TravelerModel traveler       = await acm.GetTravelerByEmail(loginManager.GetUsername());
                    traveler.InformedConsent     = true;
                    traveler.InformedConsentDate = DateTime.UtcNow;

                    traveler = await acm.UpdateTraveler(traveler);

                    NavigationController.PopViewControllerAnimated(true);

                    if (LoginEvent != null)
                    {
                        LoginEvent();
                    }
                }
            });
        }
Exemplo n.º 5
0
        public async Task <LoginResult> Register(string username, string password, string firstname, string lastname)
        {
            LoginResult loginResult = await MobileService.Register(username, password);

            if (loginResult.Success)
            {
                TravelerModel traveler = new TravelerModel();
                traveler.Email               = username;
                traveler.FirstName           = firstname;
                traveler.MiddleName          = "";
                traveler.LastName            = lastname;
                traveler.DefaultBicycleFlag  = false;
                traveler.DefaultMobilityFlag = false;
                traveler.LoginId             = loginResult.UserId;
                traveler.PhoneNumber         = "000-000-0000";
                traveler.InformedConsent     = false;
                traveler.DefaultPriority     = "1";
                traveler.DefaultTimezone     = "EST";

                TravelerModel newTraveleraccount = accountManager.CreateTraveler(traveler);

                StoreCredentials(loginResult.UserName, loginResult.UserId, loginResult.UserToken, newTraveleraccount.Id, newTraveleraccount.FirstName);
            }

            return(loginResult);
        }
Exemplo n.º 6
0
        public async Task <TravelerModel> UpdateTraveler(TravelerModel traveler)
        {
            TravelerModel travelerResult = await Task.Factory.StartNew <TravelerModel>(() =>
            {
                var client           = new RestClient(URI_STRING);
                client.Authenticator = new HttpBasicAuthenticator(HttpAuthUsername, HttpAuthPassword);

                var request = new RestRequest("/api/Traveler/" + traveler.Id, Method.PUT);

                request.RequestFormat = DataFormat.Json;

                request.AddBody(traveler);

                IRestResponse <TravelerModel> response = client.Execute <TravelerModel>(request);

                if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    throw new Exception(response.StatusDescription);
                }

                return(response.Data);
            });

            return(travelerResult);
        }
Exemplo n.º 7
0
        public async void OnResume()
        {
            loginManager = AndroidLoginManager.Instance(activity.ApplicationContext);
            if (await loginManager.IsLoggedIn())
            {
                TravelerModel traveler = await new AccountManager().GetTravelerById(loginManager.GetTravelerId());

                if (traveler.InformedConsent == false)
                {
                    loginManager.Logout();
                    activity.StartActivity(typeof(LoginActivity));
                    activity.Finish();
                }
                else
                {
                    LoadTrips();
                    RegisterGCM(activity);
                }
            }
            else
            {
                //Display the login screen
                activity.StartActivity(typeof(LoginActivity));
                activity.Finish();
            }
        }
Exemplo n.º 8
0
 public AccountInfoModel(TravelerModel traveler)
 {
     this.PromoCodeUpdated    = false;
     this.PromoCodeValid      = false;
     this.PromoCode           = traveler.PromoCode;
     this.Email               = traveler.Email;
     this.DefaultBicycleFlag  = traveler.DefaultBicycleFlag;
     this.DefaultMobilityFlag = traveler.DefaultMobilityFlag;
 }
Exemplo n.º 9
0
        public async Task <ActionResult> Manage(string email)
        {
            AccountViewModel   model = new AccountViewModel();
            LocalPasswordModel localPasswordModel = new LocalPasswordModel();

            TravelerModel traveler = await loginManager.GetTravelerByEmail(email);

            model.accountInfoModel = new AccountInfoModel(traveler);
            model.traveler         = traveler;

            return(View(model));
        }
Exemplo n.º 10
0
        public async Task <List <Trip> > GetPastTrips(string email)
        {
            TravelerModel traveler      = accountManager.GetTravelerByEmail(email);
            List <Trip>   upcomingTrips = await mTripManager.GetTripsByTypeAsync(traveler.Id, TripType.Type.Past);

            if (upcomingTrips.Count > 0)
            {
                return(upcomingTrips);
            }

            return(null);
        }
Exemplo n.º 11
0
        public async Task <LoginResult> ChangePassword(string username, string oldPassword, string newPassword)
        {
            LoginResult loginResult = await MobileService.ChangePassword(username, oldPassword, newPassword);

            if (loginResult.Success)
            {
                TravelerModel travelerAccount = accountManager.GetTravelerByEmail(username);

                StoreCredentials(loginResult.UserName, loginResult.UserId, loginResult.UserToken, travelerAccount.Id, travelerAccount.FirstName);
            }

            return(loginResult);
        }
Exemplo n.º 12
0
        public IHttpActionResult PutTraveler(int id, [FromBody] TravelerModel traveler)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != traveler.Id)
            {
                return(BadRequest());
            }

            //Check for promo code
            if (!String.IsNullOrEmpty(traveler.PromoCode))
            {
                List <PromoCode> promoCodes = Uow.Repository <PromoCode>().Query().Get().Where(t => t.Code == traveler.PromoCode).ToList();

                if (promoCodes.Count <= 0)
                {
                    return(BadRequest("Invalid Promo Code"));
                }
            }

            Traveler travelerEntity = traveler.ToTraveler();

            //Set modified date to now.
            travelerEntity.ModifiedDate = DateTime.UtcNow;

            Uow.Repository <Traveler>().Update(travelerEntity);

            try
            {
                Uow.Save();
                TravelerModel tm = new TravelerModel(travelerEntity);
                return(Ok(tm));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TravelerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Exemplo n.º 13
0
        public async Task <String> AddPromoCode(string code)
        {
            AccountManager acm      = new AccountManager();
            TravelerModel  traveler = await acm.GetTravelerByEmail(username);

            traveler.PromoCode = code;
            try
            {
                traveler = await acm.UpdateTraveler(traveler);
            }catch (Exception ex)
            {
                return(ex.Message);
            }

            return("Set Promo Code");
        }
Exemplo n.º 14
0
        public async void accpetTerms()
        {
            AndroidLoginManager loginManager = AndroidLoginManager.Instance(activity.ApplicationContext);
            string email = loginManager.GetUsername();

            AccountManager acm      = new AccountManager();
            TravelerModel  traveler = await acm.GetTravelerByEmail(email);

            traveler.InformedConsent     = true;
            traveler.InformedConsentDate = DateTime.UtcNow;
            traveler = await acm.UpdateTraveler(traveler);

            Intent intent = new Intent(activity.ApplicationContext, typeof(HomeActivity));

            activity.StartActivity(intent);
            activity.Finish();
        }
Exemplo n.º 15
0
        public Trip GetNextTrip(string email)
        {
            TravelerModel traveler = accountManager.GetTravelerByEmail(email);

            if (traveler == null)
            {
                return(null);
            }

            List <Trip> upcomingTrips = mTripManager.GetTripsByType(traveler.Id, TripType.Type.Upcoming);

            if (upcomingTrips.Count > 0)
            {
                return(upcomingTrips[0]);
            }

            return(null);
        }
Exemplo n.º 16
0
        public async Task <TravelerModel> GetTravelerByEmail(string email)
        {
            TravelerModel traveler = await Task.Factory.StartNew <TravelerModel> (() => {
                var client           = new RestClient(URI_STRING);
                client.Authenticator = new HttpBasicAuthenticator(HttpAuthUsername, HttpAuthPassword);

                var request           = new RestRequest("/api/Traveler", Method.GET);
                request.RequestFormat = DataFormat.Json;

                request.AddParameter("email", email);

                IRestResponse <TravelerModel> response = client.Execute <TravelerModel> (request);

                return(response.Data);
            });

            return(traveler);
        }
Exemplo n.º 17
0
        protected override async void OnRegistered(Context context, string registrationId)
        {
            Log.Info("IDTO", "GCM Registered: " + registrationId);
            RegistrationID = registrationId;
            Hub            = new NotificationHub(Constants.NotificationHubPath, Constants.ConnectionString);
            try {
                await Hub.UnregisterAllAsync(registrationId);
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }


            AndroidLoginManager loginMngr = AndroidLoginManager.Instance(context);

            if (!await loginMngr.IsLoggedIn())
            {
                Log.Info("IDTO", "HandleRegistration Error: Not logged in");
                return;
            }
            int           travelerID = loginMngr.GetTravelerId();
            TravelerModel traveler   = await new AccountManager().GetTravelerById(travelerID);
            string        email      = "";

            if (traveler != null)
            {
                email = traveler.Email;
            }
            var tags = new List <string> ()
            {
                email,
                travelerID.ToString()
            };

            try {
                NativeRegistration = await Hub.RegisterNativeAsync(registrationId, tags);

                ISharedPreferencesEditor editor = GetPreferences(context).Edit();
                editor.PutBoolean(KEY_REGISTERED, true);
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 18
0
        public async Task <TravelerModel> CreateTraveler(TravelerModel traveler)
        {
            TravelerModel travelerResult = await Task.Factory.StartNew <TravelerModel> (() => {
                var client           = new RestClient(URI_STRING);
                client.Authenticator = new HttpBasicAuthenticator(HttpAuthUsername, HttpAuthPassword);

                var request = new RestRequest("/api/Traveler", Method.POST);

                request.RequestFormat = DataFormat.Json;

                request.AddBody(traveler);

                IRestResponse <TravelerModel> response = client.Execute <TravelerModel> (request);

                return(response.Data);
            });

            return(travelerResult);
        }
Exemplo n.º 19
0
        public async Task <LoginResult> Login(string username, string password)
        {
            LoginResult loginResult = await MobileService.Login(username, password);

            if (loginResult.Success)
            {
                AccountManager accountManager = new AccountManager();

                TravelerModel travelerAccount = await accountManager.GetTravelerByEmail(username);

                StoreCredentials(loginResult.UserName, loginResult.UserId, loginResult.UserToken, travelerAccount.Id);
            }
            else
            {
                this.Logout();
            }

            return(loginResult);
        }
Exemplo n.º 20
0
        async partial void SubmitLogin(NSObject sender)
        {
            showLoading();


            iOSLoginManager loginManager = iOSLoginManager.Instance;

            String username = txtEmailAddress.Text;
            String password = txtPassword.Text;

            LoginResult loginResult = await loginManager.Login(username, password);

            dismissLoading();


            GAI.SharedInstance.DefaultTracker.Send(GAIDictionaryBuilder.CreateEvent("ui_action", "user login", "login result", Convert.ToInt32(loginResult.Success)).Build());

            if (loginResult.Success)
            {
                //check for terms acceptance
                AccountManager acm = new AccountManager();

                TravelerModel traveler = await acm.GetTravelerByEmail(username);

                if (!traveler.InformedConsent)
                {
                    PerformSegue("LoginTermsSegue", this);
                }
                else
                {
                    if (LoginEvent != null)
                    {
                        LoginEvent();
                    }
                }
            }
            else
            {
                UIAlertView alert = new UIAlertView("Error", loginResult.ErrorString, null, "OK", null);
                alert.Show();
            }
        }
Exemplo n.º 21
0
        public TravelerModel CreateTraveler(TravelerModel traveler)
        {
            TravelerModel travelerResult = new TravelerModel();

            var client = new RestClient(BaseUrl);

            client.Authenticator = new HttpBasicAuthenticator(HttpAuthUsername, HttpAuthPassword);

            var request = new RestRequest("/Traveler", Method.POST);

            request.RequestFormat = DataFormat.Json;

            request.AddBody(traveler);

            IRestResponse <TravelerModel> response = client.Execute <TravelerModel>(request);

            travelerResult = response.Data;

            return(travelerResult);
        }
Exemplo n.º 22
0
        public TravelerModel GetTravelerByEmail(string email)
        {
            TravelerModel traveler = new TravelerModel();

            var client = new RestClient(BaseUrl);

            client.Authenticator = new HttpBasicAuthenticator(HttpAuthUsername, HttpAuthPassword);

            var request = new RestRequest("/Traveler", Method.GET);

            request.RequestFormat = DataFormat.Json;

            request.AddParameter("email", email);

            IRestResponse <TravelerModel> response = client.Execute <TravelerModel>(request);

            traveler = response.Data;

            return(traveler);
        }
Exemplo n.º 23
0
        public async void OnAttemptLogin(string email, string password)
        {
            try{
                if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
                {
                    view.OnLoginError("You must enter a username and password");
                }
                else
                {
                    AndroidLoginManager loginManager = AndroidLoginManager.Instance(activity.ApplicationContext);
                    LoginResult         loginResult  = await loginManager.Login(email, password);

                    view.ShowBusy(false);

                    activity.sendGaEvent("ui_action", "user login", "login result", Convert.ToInt16(loginResult.Success));
                    if (loginResult.Success)
                    {
                        AccountManager acm      = new AccountManager();
                        TravelerModel  traveler = await acm.GetTravelerByEmail(email);

                        if (traveler.InformedConsent)
                        {
                            Intent intent = new Intent(activity.ApplicationContext, typeof(HomeActivity));
                            activity.StartActivity(intent);
                            activity.Finish();
                        }
                        else
                        {
                            view.showTerms();
                        }
                    }
                    else
                    {
                        view.OnLoginError(loginResult.ErrorString);
                    }
                }
            }catch (Exception e) {
                Console.WriteLine(e);
                view.OnLoginError("Login failed");
            }
        }
Exemplo n.º 24
0
        public async void OnResume()
        {
            view.ShowBusy(true);
            AndroidLoginManager loginManager = AndroidLoginManager.Instance(activity.ApplicationContext);

            if (!await loginManager.IsLoggedIn())
            {
                GoToLoginActivity();
            }
            else
            {
                username = loginManager.GetUsername();
                view.ShowUserInfo(username);

                AccountManager acm      = new AccountManager();
                TravelerModel  traveler = await acm.GetTravelerByEmail(username);

                view.ShowPromoCode(traveler.PromoCode);
            }
            view.ShowBusy(false);
        }
Exemplo n.º 25
0
        async partial void SetPromoCodeAction(NSObject sender)
        {
            mTraveler.PromoCode = txtPromoCode.Text;

            try
            {
                mTraveler = await mACM.UpdateTraveler(mTraveler);

                UIAlertView alert = new UIAlertView("Done", "Promo Code Set.", null, "OK", null);
                alert.Show();

                txtPromoCode.ResignFirstResponder();

                txtPromoCode.Enabled   = false;
                btnSetPromoCode.Hidden = true;
            }catch (Exception ex)
            {
                UIAlertView alert = new UIAlertView("Error", "Invalid Promo Code", null, "OK", null);
                alert.Show();
            }
        }
Exemplo n.º 26
0
        public async Task <LoginResult> Login(string username, string password)
        {
            LoginResult loginResult = await MobileService.Login(username, password);

            if (loginResult.Success)
            {
                TravelerModel travelerAccount = accountManager.GetTravelerByEmail(username);

                if (travelerAccount == null)
                {
                    loginResult.ErrorString = "Account not found";
                    loginResult.Success     = false;
                }
                else
                {
                    firstName = travelerAccount.FirstName;
                    StoreCredentials(loginResult.UserName, loginResult.UserId, loginResult.UserToken, travelerAccount.Id, travelerAccount.FirstName);
                }
            }

            return(loginResult);
        }
Exemplo n.º 27
0
        public IHttpActionResult PostTraveler(TravelerModel traveler)
        {
            try{
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                //Check for promo code
                if (!String.IsNullOrEmpty(traveler.PromoCode))
                {
                    List <PromoCode> promoCodes = Uow.Repository <PromoCode>().Query().Get().Where(t => t.Code == traveler.PromoCode).ToList();

                    if (promoCodes.Count <= 0)
                    {
                        return(BadRequest("Invalid Promo Code"));
                    }
                }

                Traveler travelerEntity = traveler.ToTraveler();

                //Set creation and modified date to now.
                travelerEntity.CreatedDate  = DateTime.UtcNow;
                travelerEntity.ModifiedDate = DateTime.UtcNow;

                Uow.Repository <Traveler>().Insert(travelerEntity);
                Uow.Save();
                TravelerModel tm = new TravelerModel(travelerEntity);

                return(CreatedAtRoute("DefaultApi", new { id = tm.Id }, tm));
            }
            catch (Exception ex)
            {
                string msg = RecordException(ex, "TravelerController.PostTraveler");
                HttpResponseMessage responseMessage = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg);
                throw new HttpResponseException(responseMessage);
            }
        }
Exemplo n.º 28
0
        private async Task checkLogin()
        {
            iOSLoginManager loginManager = iOSLoginManager.Instance;
            bool            shouldLogout = NSUserDefaults.StandardUserDefaults.BoolForKey("logout_preference");

            if (shouldLogout)
            {
                loginManager.Logout();
                NSUserDefaults.StandardUserDefaults.SetBool(false, "logout_preference");
            }

            AccountManager acm      = new AccountManager();
            TravelerModel  traveler = await acm.GetTravelerByEmail(loginManager.GetUsername());

            if (traveler != null && !traveler.InformedConsent)
            {
                loginManager.Logout();
            }


            if (!await loginManager.IsLoggedIn())
            {
                PerformSegue("LoginSegue", this);
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert |
                                                             UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);

                if (CLLocationManager.LocationServicesEnabled)
                {
                    mLocationManager.StartUpdatingLocation();
                }

                await UpdateTripDisplays();
            }
        }
Exemplo n.º 29
0
        public ActionResult AddPassenger(string travelerName, string travelerLastName, string travelerCountry, string travelerIdType, string travelerIdNumber, string vacancyId)
        {
            var traveler = new TravelerModel();

            if (string.IsNullOrEmpty(travelerIdNumber))
            {
                travelerIdNumber = "0";
            }

            if (SessionData.Reservation.ReservationOwner == null)
            {
                var reservationOwner = new TravelerModel()
                {
                    TravelerFirstName = travelerLastName,
                    TravelerLastName  = travelerLastName,
                    TravelerCountry   = travelerCountry,
                    TravelerIdType    = IdType.DNI,
                    TravelerId        = travelerIdNumber
                };
                SessionData.Reservation.ReservationOwner = reservationOwner;
            }

            foreach (var vacancy in SessionData.Reservation.Vacancies)
            {
                if (vacancy.VacancyId == vacancyId)
                {
                    traveler.TravelerFirstName = travelerName;
                    traveler.TravelerLastName  = travelerLastName;
                    traveler.TravelerCountry   = travelerCountry;
                    traveler.TravelerIdType    = IdType.DNI;
                    traveler.TravelerId        = travelerIdNumber;
                    vacancy.Rooms.Min().Travelers.Add(traveler);
                }
            }

            return(Json(traveler, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 30
0
        public async Task <TravelerModel> GetTravelerByEmail(string email)
        {
            TravelerModel travelerAccount = accountManager.GetTravelerByEmail(email);

            return(travelerAccount);
        }