/// <summary>
        /// Default constructor initializes communications and the settings
        /// </summary>
        public TogglerApiInternal()
        {
            _apiCommunication = new ApiCommunication();
            SettingsReader <ApiSettings> reader = new SettingsReader <ApiSettings>();

            _settings = reader.Read(SETTINGS_FILEPATH);
        }
Example #2
0
            protected override void OnFinish()
            {
                if (UpdateType == CallBackUpdateType.None)
                {
                    return;
                }

                var api = new ApiCommunication();

                var response = api.GetBookingsAsync(Token);

                if (HomeController.IsLoggedIn)
                {
                    Events = response.Result;
                }
                else
                {
                    Events = null;
                }

                DataIdField    = "Id";
                DataTextField  = "UserName";
                DataStartField = "Date";
                DataEndField   = "EndDate";
            }
Example #3
0
        private void SendLoginInfo(object sender, EventArgs args)
        {
            if (input_Email.Text.Length > 0 && input_Password.Text.Length > 0)
            {
                btn_SendLoginInfo.Enabled = false;

                ApiCommunication.SendLoginRequest(input_Email.Text, input_Password.Text);
            }
        }
Example #4
0
            protected override void OnEventClick(EventClickArgs e)
            {
                var toBeDeleted = Convert.ToInt32(e.Id);

                var api = new ApiCommunication();

                var response = api.DeleteBooking(toBeDeleted, Token);

                Update();
            }
        public async Task <ActionResult> Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password))
            {
                var api   = new ApiCommunication();
                var token = string.Empty;

                if (model.UserName == "Admin")
                {
                    var user = new User()
                    {
                        UserName     = model.UserName,
                        UserPassword = model.Password,
                        UserRole     = "Admin"
                    };

                    token = api.PostToken(user);
                }
                else
                {
                    var user = new User()
                    {
                        UserName     = model.UserName,
                        UserPassword = model.Password,
                        UserRole     = "User"
                    };

                    token = api.PostToken(user);
                }

                if (!string.IsNullOrEmpty(token))
                {
                    TempData["isloggedin"] = "true";
                    TempData["token"]      = token;
                    //TempData["username"] = User.Identity.Name;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.LoginInfo      = "Incorrect username or password";
                    TempData["isloggedin"] = "false";
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Example #6
0
        private void SendRegistrationData()
        {
            if (!EmailValid || !Password01Valid || !Password02Valid)
            {
                return;
            }

            // Send the post. Will come back as an event
            ApiCommunication.SendNewAccountRegistrationData(
                Input_Email.Text, Input_Password_01.Text, Input_FirstName.Text, Input_LastName.Text);
        }
        private void btn_Login_Click(object sender, EventArgs e)
        {
            if (Input_Email.Text.Length > 0 && Input_Password.Text.Length > 0)
            {
                btn_Login.Enabled = false;

                ApiCommunication.SendLoginRequest(Input_Email.Text, Input_Password.Text);



                btn_Login.Enabled = true;
            }
        }
Example #8
0
        private void SendRegistrationInfo(object sender, EventArgs e)
        {
            if (!PasswordValid || !input_RegisterPassword1.Text.Equals(input_RegisterPassword2.Text))
            {
                return;
            }

            // Send the post. Will come back as an event in RegistrationActionResult
            ApiCommunication.SendNewAccountRegistrationData(
                input_Email.Text, input_RegisterPassword1.Text, input_FirstName.Text, input_LastName.Text);

            btn_SendRegistrationInfo.SetWaitingState(true, "Sending info");
        }
Example #9
0
        private void CheckIfShouldPerformLogin()
        {
            // Self explanatory
            if (!UserSettings.RememberLogin)
            {
                return;
            }

            // Check if the email and pw are saved (should be at this point) and perform login
            if (UserSettings.UserEmail.Length > 0 && UserSettings.UserPassword.Length > 0)
            {
                ApiCommunication.SendLoginRequest(UserSettings.UserEmail, UserSettings.UserPassword);
            }
        }
Example #10
0
        private async void btn_DeleteFiles_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < CurrentShownFiles.Count; i++)
            {
                if (CurrentShownFiles[i] == null || CurrentShownFiles[i].CurrentState == FileStatus.Deleted)
                {
                    continue;
                }

                if (CurrentShownFiles[i].IsSelected)
                {
                    bool success = await ApiCommunication.DeleteFileRequest(CurrentShownFiles[i].FileStructOnline.FullName, UserSettings.UserAccessToken, i);
                }
            }
        }
Example #11
0
        private async void GetOnlineFiles()
        {
            FileDataList = await ApiCommunication.RequestHostedFilesList(UserSettings.UserAccessToken);

            if (FileDataList == null)
            {
                return;
            }

            foreach (OnlineFileStructure f in FileDataList)
            {
                AddFileVisual(f);
            }

            GetThumbnails();
        }
        private async void btn_SendForgotPW_Click(object sender, EventArgs e)
        {
            Task <IActionApiResponse> response = ApiCommunication.SendPasswordRecoveryRequest(input_ForgotPW_Email.Text);

            IActionApiResponse model = await response;

            if (model.Successful)
            {
                label_EmailRecoverySuccess.Visible = true;
            }
            else
            {
                label_InvalidEmail.Visible = true;
                label_InvalidEmail.Text    = model.Response.ReasonPhrase;
            }
        }
Example #13
0
        private async void FileDownloadSuccessful(object sender, FileDownloadResultEventArgs e)
        {
            CurrentShownFiles[e.ID].progress_Download.Visible = false;
            CurrentShownFiles[e.ID].panel_CheckMark.Visible   = true;
            CurrentShownFiles[e.ID].panel_CheckMark.Invalidate();
            CurrentShownFiles[e.ID].CurrentState = FileStatus.Finished;

            if (check_DeleteAfterDownload.Checked)
            {
                if (CurrentShownFiles[e.ID].CurrentState != FileStatus.Deleted)
                {
                    bool success = await ApiCommunication.DeleteFileRequest(CurrentShownFiles[e.ID].FileStructOnline.FullName, UserSettings.UserAccessToken, e.ID);
                }
            }

            DownloadNextFile();
        }
Example #14
0
            protected override void OnTimeRangeSelected(TimeRangeSelectedArgs e)
            {
                var toBeCreated = new Booking
                {
                    Date     = e.Start,
                    UserName = Username
                };

                var api = new ApiCommunication();

                if (e.Start.Hour >= 8 && e.End.Hour <= 17)
                {
                    var response = api.PostBooking(toBeCreated, Token);
                }

                Update();
            }
        private async void btn_Submit_Click(object sender, EventArgs e)
        {
            if (!PasswordsMatch || !PasswordValid || !OldPasswordValid)
            {
                return;
            }

            Task <IActionApiResponse> response = ApiCommunication.SendChangePasswordRequest(
                input_OldPassword.Text, Input_Password_01.Text, UserSettings.UserAccessToken);

            IActionApiResponse model = await response;



            if (model.Successful)
            {
                // Save the new password if needed
                if (UserSettings.RememberLogin)
                {
                    UserSettings.UserPassword = Input_Password_01.Text;
                }

                input_OldPassword.Text        = "";
                Input_Password_01.Text        = "";
                Input_Password_02.Text        = "";
                btn_SubmitNewPassword.Enabled = false;
                panel_PasswordChecks.Visible  = false;
                label_Result.Text             = "Success!";
                label_Result.Visible          = true;
                label_Result.Location         = new Point(120, 270);
            }
            else
            {
                input_OldPassword.Text       = "";
                Input_Password_01.Text       = "";
                Input_Password_02.Text       = "";
                panel_PasswordChecks.Visible = false;
                label_Result.Text            = model.Response.ReasonPhrase;
                label_Result.Visible         = true;
                label_Result.Location        = new Point(120, 270);
            }
        }
Example #16
0
 private async void SendMessages(IEnumerable <IWorkItemBase> messages)
 {
     try
     {
         ApiCommunication api = new ApiCommunication(Project);
         if (messages != null)
         {
             foreach (var message in messages)
             {
                 await api.SendMessage(message);
             }
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(
             "W aplikacji wystąpił błąd!\n" + e, "Błąd!",
             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         throw;
     }
 }
        public async Task <ActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
            {
                var api = new ApiCommunication();

                var user = new User
                {
                    UserName     = model.UserName,
                    UserEmail    = model.Email,
                    UserPassword = model.Password
                };

                var response = api.PostRegister(user);

                if (response == true)
                {
                    ViewBag.registered = "Account registered, you can now log in.";
                    return(View());
                }
                else
                {
                    ViewBag.registered = "An error occured during registration.";
                }
                return(View());
            }
            else
            {
                return(View());
            }
        }
Example #18
0
 private async void StartFileDownload(int id)
 {
     CurrentShownFiles[id].progress_Download.Visible = true;
     bool success = await ApiCommunication.DownloadFile(CurrentShownFiles[id].FileStructOnline.FullName, id, UserSettings.UserAccessToken);
 }
Example #19
0
        private async void GetThumbnails()
        {
            if (FileDataList == null)
            {
                return;
            }

            for (int i = 0; i < CurrentShownFiles.Count; i++)
            {
                if (CurrentShownFiles[i] == null || CurrentShownFiles[i].CurrentState == FileStatus.Deleted)
                {
                    continue;
                }

                FileVisualDisplay fVis = CurrentShownFiles[i];

                if (fVis.FileStructOnline.Thumbnail.Length > 0)
                {
                    byte[] thumbnailBytes = await ApiCommunication.GetThumbnail(fVis.FileStructOnline.Thumbnail, UserSettings.UserAccessToken);

                    if (thumbnailBytes == null)
                    {
                        Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
                        fVis.panel_Thumbnail.BackgroundImage = thumb;
                        continue;
                    }

                    Image thumbnail = Image.FromStream(new MemoryStream(thumbnailBytes));

                    if (fVis != null)
                    {
                        fVis.panel_Thumbnail.BackgroundImage = ImageEditing.AddThumbnailShadow((Bitmap)thumbnail, shadow_base);
                    }
                }
                else
                {
                    Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
                    fVis.panel_Thumbnail.BackgroundImage = thumb;
                }
            }

            //foreach(FileVisualDisplay fVis in CurrentShownFiles)
            //{
            //    if(fVis.FileStructOnline.Thumbnail.Length > 0)
            //    {
            //        byte[] thumbnailBytes = await ApiCommunication.GetThumbnail(fVis.FileStructOnline.Thumbnail, UserSettings.UserAccessToken);

            //        if (thumbnailBytes == null)
            //        {
            //            Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
            //            fVis.panel_Thumbnail.BackgroundImage = thumb;
            //            continue;
            //        }

            //        Image thumbnail = Image.FromStream(new MemoryStream(thumbnailBytes));

            //        fVis.panel_Thumbnail.BackgroundImage = thumbnail;
            //    }
            //    else
            //    {
            //        Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
            //        fVis.panel_Thumbnail.BackgroundImage = thumb;
            //    }
            //}
        }
 private void btn_Logout_Click(object sender, EventArgs e)
 {
     ApiCommunication.Logout();
     this.Close();
 }
 public AccountController()
 {
     _apiComm = new ApiCommunication();
 }