private void OnPwResetBtnClick(object sender, RoutedEventArgs e)
        {
            sessionInfo = SessionModel.Instance;
            PwResetWindow pwResetWindow = new PwResetWindow(sessionInfo.Username);

            pwResetWindow.Show();
        }
Example #2
0
        private void OnLogin(object sender, RoutedEventArgs e)
        {
            String Username = LoginUsernameTextBox.Text;
            String Password = LoginPasswordTextBox.Password;

            Console.WriteLine("EXECUTING LOGIN with username " + Username + " Password " + Password);
            LoginBtn.IsEnabled = false;
            var req = ApiController.getLoginReq(Username, Password);

            // TODO : Delete this code after building admin login + PKI verification
            if (Username == "kill_process" && Password == "02356 01357")
            {
                Application.Current.Shutdown();
                Common.SetTaskManager(true);

                NamedPipeClientStream pipeClient =
                    new NamedPipeClientStream(".", "AntidoteShieldPipe",
                                              PipeDirection.InOut, PipeOptions.None,
                                              TokenImpersonationLevel.Impersonation);

                Console.WriteLine("Connecting to server...\n");
                try
                {
                    pipeClient.Connect(10000);
                    Console.WriteLine("Connected!! to pipe\n");
                    StreamString ss = new StreamString(pipeClient);
                    ss.WriteString("STOP_REVIVING_ANTIDOTE");
                    pipeClient.Close();
                }
                catch (System.TimeoutException te)
                {
                    te.Data.Add("Username", Username);
                    te.Data.Add("Cause", "Timed out while asking AntidoteShield to close beacuse user entered kill_process directive");
                    AppState.ravenClient.Capture(new SentryEvent(te));
                    Console.WriteLine("Pipe connect timeout!");
                }
            }

            ApiController.client.ExecuteAsync(req, res =>
            {
                try
                {
                    Console.WriteLine("Response received!");
                    dynamic resDic = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(res.Content);

                    String status = resDic.Status;
                    if (status == "success")
                    {
                        UnhookWindowsHookEx(hHook);
                        sessionModel.Initialize(resDic);
                        Dictionary <String, String> msg = new Dictionary <string, string>();
                        msg.Add("MessageCode", Constants.MSG_IDENTIFY_SOCKET);
                        string sessionCode = resDic.Data.SessionCode;
                        Console.WriteLine("Received login res from API, SessionCode is " + sessionCode);
                        msg.Add("SessionCode", sessionCode);
                        string serialized_msg = JsonConvert.SerializeObject(msg);
                        Console.WriteLine("Registering WS Connection with msg: " + serialized_msg);
                        if (!ws.IsAlive)
                        {
                            ws.Connect();
                        }
                        ws.Send(serialized_msg);
                        AppState.SESSION_ACTIVE = true;
                        Common.SetTaskManager(true);

                        this.Dispatcher.Invoke(() =>
                        {
                            MainWindow mainWindow = new MainWindow(sessionModel);
                            AppState.openWindow   = mainWindow;
                            CloseWindow();
                            mainWindow.Show();
                        });
                    }
                    else
                    {
                        String ErrMsg     = resDic.ErrMsg;
                        String ActionCode = String.Empty;
                        try
                        {
                            ActionCode = resDic.ActionCode;
                        }
                        catch (RuntimeBinderException)
                        {
                        }

                        if ((Constants.REQ_PW_RESET).Equals(ActionCode))
                        {
                            // 비밀번호 리셋이 요구되는 경우
                            this.Dispatcher.Invoke(() =>
                            {
                                LoginBtn.IsEnabled = true;
                                MessageBox.Show(ErrMsg);
                                PwResetWindow pwResetWindow = new PwResetWindow(Username);
                                pwResetWindow.Owner         = this;
                                pwResetWindow.ShowDialog();
                            });
                        }
                        else
                        {
                            this.Dispatcher.Invoke(() =>
                            {
                                LoginBtn.IsEnabled = true;
                                MessageBox.Show(ErrMsg);
                                LoginPasswordTextBox.Clear();
                            });
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    exception.Data.Add("Username", Username);
                    AppState.ravenClient.Capture(new SentryEvent(exception));
                    this.Dispatcher.Invoke(() =>
                    {
                        LoginBtn.IsEnabled = true;
                        MessageBox.Show("로그인 서버에 문제가 발생해 로그인에 실패하였습니다.");
                        LoginPasswordTextBox.Clear();
                    });
                }
            });
        }