Exemplo n.º 1
0
 protected void AuthenticateUserToken(string usertoken)
 {
     if (!MyUserService.AuthenticateUserToken(usertoken))
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }
Exemplo n.º 2
0
        public ActionResult GetUserInfo()
        {
            MyUser user = new MyUser()
            {
                Username = (string)Session["AccountName"]
            };

            user = MyUserService.GetUserInfo(user);
            return(Json(user));
        }
Exemplo n.º 3
0
        public ActionResult ChangeUserInfo(MyUser user)
        {
            user.Username = (string)Session["AccountName"];
            int count = MyUserService.ChangeUserInfo(user);

            if (count > 0)
            {
                return(Json(new { result = true, tip = "修改信息成功" }));
            }
            return(Json(new { result = false, tip = "由于未知原因,修改信息失败" }));
        }
        public LoginPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                  LoginService loginService, MyUserService myUserService, SystemStatusService systemStatusService,
                                  AppStatus appStatus, RecordCacheHelper recordCacheHelper)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            this.loginService        = loginService;
            this.myUserService       = myUserService;
            this.systemStatusService = systemStatusService;
            this.appStatus           = appStatus;
            this.recordCacheHelper   = recordCacheHelper;

            #region 登入按鈕命令
            LoginCommand = new DelegateCommand(async() =>
            {
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,使用者登入驗證中...", null, null, true, MaskType.Black))
                {
                    LoginRequestDto loginRequestDTO = new LoginRequestDto()
                    {
                        Account  = Account,
                        Password = Password,
                    };
                    var fooResult = await LoginUpdateTokenHelper.UserLoginAsync(dialogService, loginService, systemStatusService,
                                                                                loginRequestDTO, appStatus);
                    if (fooResult == false)
                    {
                        await dialogService.DisplayAlertAsync("登入驗證失敗", "請重新輸入正確的帳號與密碼", "確定");
                        return;
                    }
                    await recordCacheHelper.RefreshAsync(fooIProgressDialog);
                    #region 取得 使用者清單
                    fooIProgressDialog.Title = "請稍後,取得 使用者清單";
                    await myUserService.ReadFromFileAsync();
                    APIResult apiResult = await myUserService.GetAsync();
                    if (apiResult.Status == true)
                    {
                        await myUserService.WriteToFileAsync();
                    }
                    #endregion
                }

                await navigationService.NavigateAsync("/MDPage/NaviPage/HomePage");
            });
            #endregion

            #region 切換使用者
            SwitchUserCommand = new DelegateCommand <string>(x =>
            {
                Account = x;
            });
            #endregion
        }
 public SplashPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                            SystemStatusService systemStatusService, SystemEnvironmentsService systemEnvironmentsService,
                            MyUserService myUserService,
                            RecordCacheHelper recordCacheHelper, AppStatus appStatus)
 {
     this.navigationService         = navigationService;
     this.dialogService             = dialogService;
     this.systemStatusService       = systemStatusService;
     this.systemEnvironmentsService = systemEnvironmentsService;
     this.myUserService             = myUserService;
     this.recordCacheHelper         = recordCacheHelper;
     this.appStatus = appStatus;
 }
Exemplo n.º 6
0
        public ActionResult Index()
        {
            ActionResult returnAction = View();

            // Verify user had admin rights
            CookieUser cUser = Newtonsoft.Json.JsonConvert.DeserializeObject <CookieUser>(Request.Cookies[Constants._COOKIE_NAME_].Value);

            if (!MyUserService.ValidateUserAdmin(cUser.UserToken))
            {
                returnAction = RedirectToAction("Logout", "Account");
            }

            return(returnAction);
        }
        public MDPageViewModel(INavigationService navigationService,
                               IPageDialogService dialogService, MyUserService myUserService,
                               LoginService loginService, SystemStatusService systemStatusService,
                               AppStatus appStatus, RecordCacheHelper recordCacheHelper,
                               LogoutCleanHelper logoutCleanHelper)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            this.myUserService       = myUserService;
            this.loginService        = loginService;
            this.systemStatusService = systemStatusService;
            this.appStatus           = appStatus;
            this.recordCacheHelper   = recordCacheHelper;
            this.logoutCleanHelper   = logoutCleanHelper;

            #region 一般命令
            MenuCommand = new DelegateCommand <string>(async x =>
            {
                switch (x)
                {
                case "首頁":
                    await navigationService.NavigateAsync("/MDPage/NaviPage/HomePage");
                    break;
                }
            });
            #endregion

            #region 登出命令
            LogoutCommand = new DelegateCommand(async() =>
            {
                var isLogout = await dialogService.DisplayAlertAsync("警告",
                                                                     "你確定要登出嗎?", "確定", "取消");
                if (isLogout == true)
                {
                    using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
                    {
                        await logoutCleanHelper.LogoutCleanAsync(fooIProgressDialog);
                        var fooResult = await LoginUpdateTokenHelper.UserLogoutAsync(dialogService, loginService, systemStatusService, appStatus);
                        if (fooResult == true)
                        {
                            await navigationService.NavigateAsync("/LoginPage");
                        }
                    }
                }
            });
            #endregion
        }
Exemplo n.º 8
0
        public ActionResult ChangeUserPassword(string oldPassword, string newPassword)
        {
            string username = (string)Session["AccountName"];
            MyUser user     = new MyUser()
            {
                Username = username, Password = oldPassword
            };

            //确认原密码正确性
            if (MyUserService.CheckUserPassword(user))
            {
                user.Password = newPassword;
                MyUserService.ChangeUserPassword(user);
                return(Json(new { result = true, tip = "修改密码成功" }));
            }
            else
            {
                return(Json(new { result = false, tip = "原密码错误,修改密码失败" }));
            }
        }
 public SplashPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                            SystemStatusService systemStatusService, SystemEnvironmentsService systemEnvironmentsService,
                            ProjectService projectService, MyUserService myUserService,
                            RecordCacheHelper recordCacheHelper, AppStatus appStatus,
                            ExceptionRecordsService exceptionRecordsService, AppExceptionsService appExceptionsService,
                            LeaveCategoryService leaveCategoryService, OnCallPhoneService onCallPhoneService)
 {
     this.navigationService         = navigationService;
     this.dialogService             = dialogService;
     this.systemStatusService       = systemStatusService;
     this.systemEnvironmentsService = systemEnvironmentsService;
     this.projectService            = projectService;
     this.myUserService             = myUserService;
     this.recordCacheHelper         = recordCacheHelper;
     this.appStatus = appStatus;
     this.exceptionRecordsService = exceptionRecordsService;
     this.appExceptionsService    = appExceptionsService;
     this.leaveCategoryService    = leaveCategoryService;
     this.onCallPhoneService      = onCallPhoneService;
 }
        public OnCallPhonePageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                        OnCallPhoneService onCallPhoneService,
                                        MyUserService myUserService,
                                        RefreshTokenService refreshTokenService,
                                        SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            this.onCallPhoneService  = onCallPhoneService;
            this.myUserService       = myUserService;
            this.refreshTokenService = refreshTokenService;
            this.systemStatusService = systemStatusService;
            this.appStatus           = appStatus;

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                try
                {
                    PhoneDialer.Open(SelectedItem.PhoneNumber);
                }
                catch (Exception ex)
                {
                    await dialogService.DisplayAlertAsync("錯誤", $"發生例外異常:{ex.Message}", "確定");
                }
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion
        }
Exemplo n.º 11
0
        public async Task <MyUserAdapterModel> GetCurrentUserAsync()
        {
            #region  取得現在登入使用者資訊
            if (CustomUserId != 0)
            {
                var myUser = await MyUserService.GetAsync(CustomUserId);

                CurrentMyUserAdapterModel = myUser;
                return(myUser);
            }
            else
            {
                var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

                var user = authState.User;
                if (user.Identity.IsAuthenticated)
                {
                    var myUserId = Convert.ToInt32(user.FindFirst(c => c.Type == ClaimTypes.Sid)?.Value);
                    var myUser   = await MyUserService.GetAsync(myUserId);

                    if (myUser.Id == 0)
                    {
                        return(null);
                    }
                    var myUserAdapterModel = Mapper.Map <MyUserAdapterModel>(myUser);
                    CurrentMyUserAdapterModel = myUserAdapterModel;

                    return(myUserAdapterModel);
                }
                else
                {
                    CurrentMyUserAdapterModel = null;
                    return(null);
                }
            }
            #endregion
        }
Exemplo n.º 12
0
 public LoginResponse ValidateUser(string email, string password)
 {
     return(MyUserService.ValidateUser(email, password));
 }
Exemplo n.º 13
0
 protected bool AuthenticateUserToken(string usertoken)
 {
     return(MyUserService.AuthenticateUserToken(usertoken));
 }
        public LeaveFormRecordPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                            LeaveFormService leaveFormService, LeaveCategoryService leaveCategoryService,
                                            MyUserService myUserService,
                                            RefreshTokenService refreshTokenService,
                                            SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService    = navigationService;
            this.dialogService        = dialogService;
            this.leaveFormService     = leaveFormService;
            this.leaveCategoryService = leaveCategoryService;
            this.myUserService        = myUserService;
            this.refreshTokenService  = refreshTokenService;
            this.systemStatusService  = systemStatusService;
            this.appStatus            = appStatus;

            #region 新增 儲存 按鈕命令
            SaveCommand = new DelegateCommand(async() =>
            {
                #region 進行資料完整性檢查
                SelectedItem.CombineDate();
                var checkResult = SelectedItem.Validation();
                if (!string.IsNullOrEmpty(checkResult))
                {
                    await dialogService.DisplayAlertAsync("錯誤", $"請檢查並且修正錯誤{Environment.NewLine}{Environment.NewLine}" +
                                                          $"{checkResult}", "確定");
                    return;
                }
                #endregion

                #region 進行記錄儲存
                APIResult apiResult = new APIResult();
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,儲存資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    if (CrudAction == MagicStringHelper.CrudAddAction)
                    {
                        #region 新增 請假單
                        fooIProgressDialog.Title = "請稍後,新增 請假單";
                        SelectedItem.Id          = 0;
                        apiResult = await leaveFormService.PostAsync(SelectedItem);
                        if (apiResult.Status == true)
                        {
                            ToastHelper.ShowToast($"請假單 已經新增");

                            NavigationParameters paras = new NavigationParameters();
                            paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                            await navigationService.GoBackAsync(paras);
                        }
                        else
                        {
                            await dialogService.DisplayAlertAsync("錯誤", $"請假單 儲存失敗:{apiResult.Message}", "確定");
                        }
                        #endregion
                    }
                    else
                    {
                        #region 儲存 請假單
                        fooIProgressDialog.Title = "請稍後,儲存 請假單";
                        apiResult = await leaveFormService.PutAsync(SelectedItem);
                        if (apiResult.Status == true)
                        {
                            ToastHelper.ShowToast($"請假單 已經儲存");

                            NavigationParameters paras = new NavigationParameters();
                            paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                            await navigationService.GoBackAsync(paras);
                        }
                        else
                        {
                            await dialogService.DisplayAlertAsync("錯誤", $"請假單 儲存失敗:{apiResult.Message}", "確定");
                        }
                        #endregion
                    }

                    #region 取得 請假單
                    fooIProgressDialog.Title = "請稍後,取得 請假單";
                    apiResult = await leaveFormService.GetAsync();
                    if (apiResult.Status == true)
                    {
                        await leaveFormService.WriteToFileAsync();
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"取得 請假單 失敗:{apiResult.Message}", "確定");
                    }
                    #endregion
                }
                #endregion
            });
            #endregion

            #region 刪除 按鈕命令
            DeleteCommand = new DelegateCommand(async() =>
            {
                #region 進行記錄刪除
                var confirm = await dialogService.DisplayAlertAsync(
                    "警告", "是否要刪除這筆紀錄?", "確定", "取消");
                if (confirm == false)
                {
                    return;
                }

                APIResult apiResult = new APIResult();
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,刪除資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    #region 刪除 請假單
                    fooIProgressDialog.Title = "請稍後,刪除 請假單";
                    apiResult = await leaveFormService.DeleteAsync(SelectedItem);
                    if (apiResult.Status == true)
                    {
                        ToastHelper.ShowToast($"請假單 已經刪除");

                        NavigationParameters paras = new NavigationParameters();
                        paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                        await navigationService.GoBackAsync(paras);
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"請假單 刪除失敗:{apiResult.Message}", "確定");
                    }
                    #endregion

                    #region 取得 請假單
                    fooIProgressDialog.Title = "請稍後,取得 請假單";
                    apiResult = await leaveFormService.GetAsync();
                    if (apiResult.Status == true)
                    {
                        await leaveFormService.WriteToFileAsync();
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"取得 請假單 失敗:{apiResult.Message}", "確定");
                    }
                    #endregion
                }
                #endregion
            });
            #endregion
        }
        public TravelExpensePageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                          TravelExpenseService travelExpenseService,
                                          MyUserService myUserService, TravelExpenseDetailService travelExpenseDetailService,
                                          RefreshTokenService refreshTokenService,
                                          SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService          = navigationService;
            this.dialogService              = dialogService;
            this.travelExpenseService       = travelExpenseService;
            this.myUserService              = myUserService;
            this.travelExpenseDetailService = travelExpenseDetailService;
            this.refreshTokenService        = refreshTokenService;
            this.systemStatusService        = systemStatusService;
            this.appStatus = appStatus;

            #region 新增紀錄
            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject       = new TravelExpenseDto();
                fooObject.ApplyDate = DateTime.Now.Date;

                #region 設定該使用者為預設紀錄申請者
                var myUser = myUserService.Items
                             .FirstOrDefault(x => x.Id == appStatus.SystemStatus.UserID);
                if (myUser != null)
                {
                    fooObject.MyUserId   = myUser.Id;
                    fooObject.MyUserName = myUser.Name;
                }
                #endregion

                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudAddAction);
                await navigationService.NavigateAsync("TravelExpenseRecordPage", paras);
            });
            #endregion

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject = SelectedItem.Clone();
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudEditAction);
                await navigationService.NavigateAsync("TravelExpenseRecordPage", paras);
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion

            #region 顯示明細頁面
            ShowDetailCommand = new DelegateCommand <TravelExpenseDto>(async x =>
            {
                #region 讀取該筆明細清單
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    #region 取得 差旅費用明細紀錄
                    fooIProgressDialog.Title = "請稍後,取得 差旅費用明細紀錄";
                    var apiResultssss        = await travelExpenseDetailService.GetAsync(x.Id);
                    if (apiResultssss.Status == true)
                    {
                        await travelExpenseDetailService.WriteToFileAsync();

                        NavigationParameters paras = new NavigationParameters();
                        paras.Add(MagicStringHelper.MasterRecordActionName, x);
                        await navigationService.NavigateAsync("TravelExpenseDetailPage", paras);
                    }
                    else
                    {
                        await DialogHelper.ShowAPIResultIsFailureMessage(dialogService, apiResultssss);
                        return;
                    }
                    #endregion
                }
                #endregion
            });
            #endregion
        }
Exemplo n.º 16
0
 public User GetUserById(string userToken, int userId)
 {
     AuthenticateUserToken(userToken);
     return(MyUserService.ReadUserById(userId));
 }
Exemplo n.º 17
0
 public VerifyResponse VerifyUserRegistration(int id, string token)
 {
     return(MyUserService.VerifyUserRegistration(id, token));
 }
Exemplo n.º 18
0
 public RegisterResponse RegisterUser([FromBody] InputUser newUser)
 {
     return(MyUserService.RegisterUser(newUser));
 }
Exemplo n.º 19
0
 public void LogoutUser(int userId)
 {
     MyUserService.LogoutUser(userId);
 }
Exemplo n.º 20
0
        public LeaveFormPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                      LeaveFormService leaveFormService, LeaveCategoryService leaveCategoryService,
                                      MyUserService myUserService,
                                      RefreshTokenService refreshTokenService,
                                      SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService    = navigationService;
            this.dialogService        = dialogService;
            this.leaveFormService     = leaveFormService;
            this.leaveCategoryService = leaveCategoryService;
            this.myUserService        = myUserService;
            this.refreshTokenService  = refreshTokenService;
            this.systemStatusService  = systemStatusService;
            this.appStatus            = appStatus;

            #region 新增紀錄
            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject          = new LeaveFormDto();
                fooObject.FormDate     = DateTime.Now.Date;
                fooObject.BeginDate    = DateTime.Now.AddDays(1).Date + new TimeSpan(09, 00, 00);
                fooObject.CompleteDate = DateTime.Now.AddDays(1).Date + new TimeSpan(18, 00, 00);
                fooObject.Hours        = 8.0m;

                #region 設定該使用者為預設紀錄申請者
                var myUser = myUserService.Items
                             .FirstOrDefault(x => x.Id == appStatus.SystemStatus.UserID);
                if (myUser != null)
                {
                    fooObject.MyUserId   = myUser.Id;
                    fooObject.MyUserName = myUser.Name;
                }
                #endregion

                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudAddAction);
                await navigationService.NavigateAsync("LeaveFormRecordPage", paras);
            });
            #endregion

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject = SelectedItem.Clone();
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudEditAction);
                await navigationService.NavigateAsync("LeaveFormRecordPage", paras);
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion
        }