示例#1
0
        public IViewComponentResult Invoke(MonthViewPagerViewModel pagerModel)
        {
            MonthViewViewModel model = null;

            if (ModelState.IsValid)
            {
                try
                {
                    model       = new MonthViewViewModel();
                    model.Pager = pagerModel;

                    UIUser usr  = GetUserInfo();
                    var    list = MonthExpensesContext.LoadUserMonthExpenses(usr, pagerModel.SelectedMonth.MonthStartTs, pagerModel.SelectedMonth.MonthEndTs).Select(x => AutoMapperFactory.MonthViewItemViewModel_UIMonthExpense.CreateMapper().Map <MonthViewItemViewModel>(new UIMonthExpense(x))).ToList();
                    model.MonthViewItems = list;
                    if (list.Count() != 0)
                    {
                        model.MonthTotalCost = list.Select(x => x.TotalCost).Sum();
                    }
                }
                catch (Exception ex)
                {
                    ViewData["WarningMessage"] = ex.Message;
                }

                return(View(model));
            }
            else
            {
                model = new MonthViewViewModel();
                model.MonthViewItems = new List <MonthViewItemViewModel>();
                model.Pager          = pagerModel;

                return(View(model));
            }
        }
示例#2
0
        public override bool IsValid(object value)
        {
            if (value is string)
            {
                string val = value as string;
                if (String.IsNullOrEmpty(val))
                {
                    ErrorMessage = "Password can not be Empty";

                    return(false);
                }
                if (!UIUser.IsValidPassword(val))
                {
                    ErrorMessage = "Invalid Password. Please follow the password policy";

                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        public bool IsExternalUser(ref UIUser usr)
        {
            ClaimsPrincipal claims          = HttpContext.User;
            var             claimExternal   = claims.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Role) && x.Value.Equals("External"));
            var             claimMember     = claims.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Role) && x.Value.Equals("Member"));
            var             claimProfilePic = claims.Claims.FirstOrDefault(x => x.Type.Equals("profile-picture"));

            if (claimExternal != null && claimMember == null)
            {
                var claimExternalId = claims.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier));
                var claimEmail      = claims.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Email));

                if (claimProfilePic != null)
                {
                    usr.ProfilePhotoUrl = claimProfilePic.Value;
                }

                usr.UserName = claimExternalId.Value;
                usr.Email    = claimEmail.Value;
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        public UIUser Login()
        {
            CurrentUser = null;
            var window = new LoginWindow(Owner, _clientProtocol);

            window.ShowDialog();
            switch (window.LoginResult)
            {
            case LoginResult.LoginResultTourist:
            {
                CurrentUser = window.User;
                break;
            }

            case LoginResult.LoginResultLoginSuccesful:
            {
                CurrentUser = window.User;
                this.GetGameRecords();
                Task.Run(() => {
                        this.GetHeadsculpt();
                    });
                break;
            }

            case LoginResult.LoginResultWorking:
            case LoginResult.LoginResultLoginFail:
            case LoginResult.LoginResultRegist:
            case LoginResult.LoginResultExit:
            default:
                CurrentUser = null;
                break;
            }
            return(CurrentUser);
        }
示例#5
0
        public virtual void StartWork(MainConfig config, Message msg)
        {
            string  error       = "账号不存在";
            UIUser  realUser    = this.FindUser(config, msg.UserID);
            Message respondsMsg = null;

            if (null != realUser)
            {
                respondsMsg = this.GetRespondsMsg(config, realUser, msg);
            }
            else
            {
                respondsMsg = new MessageError()
                {
                    User   = msg.User,
                    CallID = msg.CallID,
                    UserID = msg.UserID,
                    Error  = error,
                }
            };
            if (respondsMsg != null)
            {
                config._serverProtocol.SendMsg(respondsMsg);
            }
        }
示例#6
0
        protected override Message GetRespondsMsg(MainConfig config, UIUser localUser, Message msg)
        {
            var realMsg = msg as MessageTakeOneGameRecord;

            config._sqlServer.InsertGameRecord(localUser, realMsg.Record);
            return(null);
        }
示例#7
0
        public override bool IsValid(object value)
        {
            if (value is string)
            {
                string val = value as string;
                if (String.IsNullOrEmpty(val))
                {
                    ErrorMessage = "Username can not be Empty";

                    return(false);
                }
                if (!UIUser.IsValidUsername(val))
                {
                    ErrorMessage = "Invalid Username";

                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
 private void OnTourist(object sender, RoutedEventArgs e)
 {
     User           = new UIUser("123456", "游客");
     User.Introduce = "你好呀!";
     User.ChangeHead(@"Image\Logo.ico");
     LoginResult = LoginResult.LoginResultTourist;
     VisualStateManager.GoToElementState(this, "CloseState", true);
     this.OnClose();
 }
示例#9
0
        public async Task <JsonResult> ValidateLogin(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                UIUser usr = new UIUser();
                usr.UserName = model.LoginId;
                usr.Email    = model.LoginId;
                usr.Password = model.Password;

                try
                {
                    try
                    {
                        usr.Assign(UsersContext.ValidateUser(usr));
                    }
                    catch (Exception ex)
                    {
                        ViewData["LoginErrorMessage"] = ex.Message;

                        return(this.Json("Login info does not pass validation"));
                        //return View("Login");
                    }

                    // User  Authentication handling
                    const string Issuer = "Noah Tong";
                    var          claims = new List <Claim>();
                    claims.Add(new Claim(ClaimTypes.Name, usr.FirstName + " " + usr.LastName, ClaimValueTypes.String, Issuer));
                    claims.Add(new Claim(ClaimTypes.Role, "Member", ClaimValueTypes.String, Issuer));
                    claims.Add(new Claim(ClaimTypes.UserData, usr.UserId.ToString(), ClaimValueTypes.Integer32, Issuer));
                    var userIdentity = new ClaimsIdentity("SecureLogin");
                    userIdentity.AddClaims(claims);
                    var userPrincipal = new ClaimsPrincipal(userIdentity);

                    await HttpContext.Authentication.SignInAsync("CookieMiddlewareInstance", userPrincipal,
                                                                 new AuthenticationProperties
                    {
                        IsPersistent = model.RememberMe,
                        AllowRefresh = false
                    });

                    var obj = AutoMapperFactory.AccountViewModel_UIUserMapping.CreateMapper().Map <AccountViewModel>(usr);

                    return(this.Json("Pass---" + obj.DefaultController + "/" + obj.DefaultView));
                }
                catch (Exception ex)
                {
                    ViewData["LoginErrorMessage"] = ex.Message;

                    return(this.Json("Login info does not pass validation"));
                    //return View("Login");
                }
            }
            else
            {
                return(this.Json("Login info does not pass validation"));
            }
        }
示例#10
0
 private void InitForm()
 {
     this.CurrModalityCode = LocalConfiguration.Instance.DefaultModalityCode;
     this.SexList = UISex.FromEntities(SexService.GetSexList());
     this.ExamTypeList = UIExamType.FromEntities(ExamTypeService.GetExamTypeList());
     this.ModalityList = UIModality.FromEntities(ModalityService.GetModalityList());
     this.DepartmentList = UIDept.FromEntities(DeptService.GetDeptList());
     this.ReportUserList = UIUser.FromEntities(UserService.GetUserList());
     this.ReviewUserList = UIUser.FromEntities(UserService.GetUserList());
     this.PatientSourceList = UIPatientList.FromEntities(PatientSourceService.GetPatientSourceList());
 }
示例#11
0
 protected override Message GetRespondsMsg(MainConfig config, UIUser localUser, Message msg)
 {
     localUser.ChangeHead(localUser.HeadImagePath);
     return(new MessageGetHeadResponds()
     {
         CallID = msg.CallID,
         User = localUser,
         UserID = localUser.ID,
         Source = localUser.HeadStream.GetBuffer(),
     });
 }
示例#12
0
 protected override Message GetRespondsMsg(MainConfig config, UIUser localUser, Message msg)
 {
     config._sqlServer.GetGameRecords(localUser);
     return(new MessageGameRecords()
     {
         CallID = msg.CallID,
         User = localUser,
         UserID = localUser.ID,
         Records = localUser.GameRecords.ToArray()
     });
 }
示例#13
0
        public IActionResult ChangePassword(PasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(model.Password) && !String.IsNullOrEmpty(model.RetryPassword))
                {
                    if (model.Password != model.RetryPassword)
                    {
                        ViewData["PasswordErrorMessage"] = "Password not matched";

                        return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
                    }
                    else if (!Regex.IsMatch(model.Password, UIUser.PasswordRegexString))
                    {
                        ViewData["PasswordErrorMessage"] = "Password does not meet the requirements";

                        return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
                    }
                    else
                    {
                        try
                        {
                            UIUser usr = new UIUser();
                            usr.UserId   = model.UserId;
                            usr.UserName = model.UserName;
                            usr.Email    = model.Email;
                            usr.Password = model.Password;

                            UsersContext.UpdateUserPassword(usr);

                            ViewData["PasswordSuccessMessage"] = "Password was updated successfully";

                            return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
                        }
                        catch (Exception ex)
                        {
                            ViewData["PasswordErrorMessage"] = ex.Message;

                            return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
                        }
                    }
                }
                else
                {
                    ViewData["PasswordErrorMessage"] = "Empty password";

                    return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
                }
            }
            else
            {
                return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
            }
        }
示例#14
0
        public AddData()
        {
            InitializeComponent();
            uiSaveData.Save.Click       += Save_Click;
            uiSaveData.RefreshAll.Click += Refresh_Click;
            uiSaveData.Cancel.Click     += Cancel_Click;
            TabChanged += Tab_Changed;

            uIPerson = new UIPerson();
            uIVendor = new UIVendor();
            uIUser   = new UIUser();
        }
示例#15
0
 public void GetGameRecords(UIUser user)
 {
     user.GameRecords.Clear();
     this.Execute($"SELECT * FROM lianliankan_game_record WHERE id = '{user.ID}' ORDER BY play_time ASC", async(reader) => {
         while (await reader.ReadAsync())
         {
             DateTime playTime = (DateTime)reader["play_time"];
             string gameTime   = reader["game_time"] as string;
             user.AddGameRecord(playTime, gameTime);
         }
     });
 }
示例#16
0
        public UIUser GetUserInfo()
        {
            UIUser ret = new UIUser();

            ClaimsPrincipal claims = HttpContext.User;
            var             claim  = claims.Claims.FirstOrDefault(x => x.Type == ClaimTypes.UserData);
            int             id     = Int32.Parse(claim.Value);

            ret.Assign(UsersContext.GetUserById(id));

            return(ret);
        }
示例#17
0
        public IViewComponentResult Invoke(AllExpensePagerViewModel pagerModel)
        {
            AllExpenseViewModel model = null;

            if (ModelState.IsValid)
            {
                try
                {
                    long   lastItemId    = 0;
                    string lastItemIdStr = HttpContext.Session.Get <string>((GetSessionPrefix() + "IM_LASTITEMID"));
                    if (!String.IsNullOrEmpty(lastItemIdStr))
                    {
                        lastItemId = long.Parse(lastItemIdStr);
                    }
                    pagerModel.LastItemId = lastItemId;

                    model       = new AllExpenseViewModel();
                    model.Pager = pagerModel;

                    UIUser usr           = GetUserInfo();
                    var    expenseCategs = LoadUserExpenseCategs(usr);
                    var    list          = ExpensesContext.LoadUserExpensesPagedNav(usr, pagerModel.StartTs, pagerModel.EndTs, pagerModel.PageSize, pagerModel.PageIndex).Select(x => AutoMapperFactory.ExpenseViewModel_UIExpense.CreateMapper().Map <ExpenseViewModel>(new UIExpense(x))).ToList();
                    foreach (var item in list)
                    {
                        item.ExpenseCateg = expenseCategs.FirstOrDefault(x => x.ExpenseCategId == item.ExpenseCategId);

                        lastItemId = item.ExpenseId;
                    }
                    model.Expenses = list;

                    HttpContext.Session.Put((GetSessionPrefix() + "IM_LASTITEMID"), lastItemId.ToString());
                }
                catch (Exception ex)
                {
                    ViewData["WarningMessage"] = ex.Message;
                }

                model.Pager.JsonConvertObject = JsonConvert.SerializeObject(model.Pager);

                return(View(model));
            }
            else
            {
                model = new AllExpenseViewModel()
                {
                    Expenses = new List <ExpenseViewModel>(), Pager = pagerModel
                };
                model.Pager.JsonConvertObject = JsonConvert.SerializeObject(model.Pager);

                return(View(model));
            }
        }
示例#18
0
        public async Task <IActionResult> LoginRouter()
        {
            if (IsGuest())
            {
                return(RedirectToAction("Login", "Account"));
            }

            UIUser usr = new UIUser();

            if (IsExternalUser(ref usr))
            {
                var refUsr = UsersContext.ValidateExternalUser(usr, "External");
                if (refUsr.UserId != 0)
                {
                    usr.Assign(refUsr);

                    // User Authentication handling
                    const string Issuer = "Noah Tong";
                    var          claims = new List <Claim>();
                    claims.Add(new Claim(ClaimTypes.Name, usr.FirstName + " " + usr.LastName, ClaimValueTypes.String, Issuer));
                    claims.Add(new Claim(ClaimTypes.Role, "Member", ClaimValueTypes.String, Issuer));
                    claims.Add(new Claim(ClaimTypes.UserData, usr.UserId.ToString(), ClaimValueTypes.Integer32, Issuer));
                    var userIdentity = new ClaimsIdentity("SecureLogin");
                    userIdentity.AddClaims(claims);
                    var userPrincipal = new ClaimsPrincipal(userIdentity);

                    await HttpContext.Authentication.SignInAsync("CookieMiddlewareInstance", userPrincipal,
                                                                 new AuthenticationProperties
                    {
                        IsPersistent = true,
                        AllowRefresh = false
                    });

                    return(RedirectToAction("LoginRed", "Redirect"));
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            else if (IsMember(ref usr))
            {
                return(RedirectToAction(usr.DefaultView, usr.DefaultController));
            }
            else
            {
                return(RedirectToAction("Forbidden", "Account"));
            }

            //return View();
        }
示例#19
0
        public override void StartWork(MainConfig config, Message msg)
        {
            var    realMsg  = msg as MessageLoginRequest;
            string error    = null;
            UIUser realUser = FindUser(config, realMsg.Account);

            if (realUser == null)
            {
                error = "账号不存在";
            }
            else if (realUser.Password != realMsg.Password)
            {
                realUser = null;
                error    = "密码错误";
            }
            else if (realUser.Client != null)
            {
                realUser = null;
                error    = "账号已登录";
            }
            Message respondsMsg = null;

            if (null != realUser)
            {
                respondsMsg = new MessageLoginResponds()
                {
                    CallID    = msg.CallID,
                    User      = realUser,
                    UserID    = realUser.ID,
                    Account   = realUser.Account,
                    Name      = realUser.Name,
                    Introduce = realUser.Introduce
                };
                realUser.Client = msg.User.Client;
                config._serverProtocol.UserList[msg.User.Client] = realUser;
            }
            else
            {
                respondsMsg = new MessageLoginFailed()
                {
                    User    = msg.User,
                    CallID  = msg.CallID,
                    UserID  = msg.UserID,
                    Account = realMsg.
                              Account, Error = error,
                }
            };
            config._serverProtocol.SendMsg(respondsMsg);
        }
    }
示例#20
0
        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (userDataGrid != e.OriginalSource)
            {
                return;
            }
            DataGrid dataGrid = sender as DataGrid;
            UIUser   user     = dataGrid.SelectedItem as UIUser;

            if (null != user)
            {
                _mainConfig._sqlServer.GetGameRecords(user);
            }
        }
示例#21
0
        protected UIUser FindUser(MainConfig config, int id)
        {
            UIUser realUser = null;

            for (int index = 0; index < config.UserList.Count; index++)
            {
                var user = config.UserList[index];
                if (user.ID == id)
                {
                    realUser = user;
                    break;
                }
            }
            return(realUser);
        }
示例#22
0
        public IHttpActionResult GetUser()
        {
            string          myId    = User.Identity.GetUserId();
            ApplicationUser appUser = db.Users.Find(myId);

            var user = new UIUser()
            {
                Id    = appUser.Id,
                Name  = appUser.Nickname,
                Email = appUser.Email,
                City  = appUser.City
            };

            return(Ok(user));
        }
示例#23
0
        public bool IsMember(ref UIUser usr)
        {
            ClaimsPrincipal claims      = HttpContext.User;
            var             claimMember = claims.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Role) && x.Value.Equals("Member"));

            if (claimMember != null)
            {
                usr = GetUserInfo();
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#24
0
 public void InitUserList(ObservableCollection <UIUser> userList)
 {
     this.Execute("SELECT * FROM lianliankan_user ORDER BY id ASC", async(reader) => {
         while (await reader.ReadAsync())
         {
             var user = new UIUser((int)(reader["id"]),
                                   reader["user_account"].ToString(),
                                   reader["user_password"].ToString(),
                                   reader["user_name"].ToString());
             user.Introduce     = reader["user_introduce"].ToString();
             user.HeadImagePath = reader["user_head_path"].ToString();
             userList.Add(user);
         }
     });
 }
示例#25
0
        public IActionResult Setting(SettingViewModel model)
        {
            if (Request.Method.Equals("GET"))
            {
                model = new SettingViewModel();

                UIUser usr = GetUserInfo();
                model          = new SettingViewModel();
                model.SiteMaps = SiteMapsContext.LoadAllSiteMaps().Select(x => AutoMapperFactory.SiteMapViewModel_UISiteMap.CreateMapper().Map <SiteMapViewModel>(new UISiteMap(x))).ToList();
                var item = model.SiteMaps.FirstOrDefault(x => x.SiteMapController.Equals(usr.DefaultController) && x.SiteMapView.Equals(usr.DefaultView));
                item.IsSelected = true;

                return(View(model));
            }
            else
            {
                UIUser           usr  = GetUserInfo();
                SiteMapViewModel item = model.SiteMaps.FirstOrDefault(x => x.IsSelected);
                if (item == null)
                {
                    ViewData["ErrorMessage"] = "Unhandled exception: item not found";
                }
                else
                {
                    bool update = false;
                    try
                    {
                        update = SiteMapsContext.UpdateUserDefaultView(usr, AutoMapperFactory.SiteMapViewModel_UISiteMap.CreateMapper().Map <UISiteMap>(item));
                    }
                    catch (Exception ex)
                    {
                        ViewData["ErrorMessage"] = ex.Message;
                    }

                    if (update)
                    {
                        ViewData["SuccessMessage"] = "Successfully updated the User Front Page...";
                    }
                    else
                    {
                        ViewData["ErrorMessage"] = "Unhandled exception: failed to update the record";
                    }
                }

                return(View(model));
            }
        }
示例#26
0
        public IActionResult EditProfile(UserDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                UIUser newUsr     = AutoMapperFactory.UserDetailViewModel_UIUserMapping.CreateMapper().Map <UIUser>(model);
                UIUser existedUsr = GetUserInfo();

                if (existedUsr.Compare(newUsr))
                {
                    ViewData["ProfileErrorMessage"] = "No change was made to User Profile";

                    return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
                }
                else
                {
                    newUsr.UserId          = existedUsr.UserId;
                    newUsr.UserName        = existedUsr.UserName;
                    newUsr.Email           = existedUsr.Email;
                    newUsr.IsActive        = existedUsr.IsActive;
                    newUsr.ProfilePhotoUrl = existedUsr.ProfilePhotoUrl;
                    newUsr.SecurityToken   = existedUsr.SecurityToken;
                    newUsr.DBInstance      = existedUsr.DBInstance;

                    try
                    {
                        newUsr.Assign(UsersContext.UpdateUserProfile(newUsr));

                        ViewData["ProfileSuccessMessage"] = "Account info was updated successfully";

                        var accountModel = AutoMapperFactory.AccountViewModel_UIUserMapping.CreateMapper().Map <AccountViewModel>(newUsr);
                        HttpContext.Session.Put(GetSessionPrefix() + "Home_Account", accountModel);
                        return(View("Account", accountModel));
                    }
                    catch (Exception ex)
                    {
                        ViewData["ProfileErrorMessage"] = ex.Message;

                        return(View("Account", AutoMapperFactory.AccountViewModel_UIUserMapping.CreateMapper().Map <AccountViewModel>(existedUsr)));
                    }
                }
            }
            else
            {
                return(View("Account", HttpContext.Session.Get <AccountViewModel>(GetSessionPrefix() + "Home_Account")));
            }
        }
示例#27
0
        public override void StartWork(MainConfig config, Message msg)
        {
            string  error;
            var     realMsg     = msg as MessageRegisterRequest;
            Message respondsMsg = null;

            if (CheckMsg(config, msg, out error))
            {
                UIUser user = new UIUser(0, realMsg.Account, realMsg.Password, realMsg.Name);
                user.Introduce = realMsg.Introduce;
                var fileName = $"User{realMsg.Account.GetHashCode()}.png";
                using (var stream = new MemoryStream(realMsg.HeadsculptStream))
                {
                    var encoder = new BmpBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(stream));
                    using (var fileStream = File.OpenWrite($@"HeadImage\{fileName}"))
                        encoder.Save(fileStream);
                }
                user.HeadImagePath = fileName;
                var realUser = config._sqlServer.InsertUser(user);
                realUser.Client = msg.User.Client;
                config._serverProtocol.UserList[realUser.Client] = realUser;
                config.UserList.Add(realUser);
                respondsMsg = new MessageRegisterSuccessfully()
                {
                    CallID = msg.CallID,
                    UserID = realUser.ID,
                    User   = realUser
                };
            }
            else
            {
                respondsMsg = new MessageRegisterFailed()
                {
                    User    = msg.User,
                    CallID  = msg.CallID,
                    UserID  = msg.UserID,
                    Account = realMsg.Account,
                    Error   = error,
                }
            };
            config._serverProtocol.SendMsg(respondsMsg);
        }
    }
示例#28
0
        public async Task <IActionResult> RegisterThroughExternal()
        {
            try
            {
                UIUser usr = new UIUser();
                if (IsExternalUser(ref usr))
                {
                    if (usr.UserId == 0)
                    {
                        UsersContext.RegisterExternalUser(usr, "External");

                        usr.Assign(UsersContext.ValidateExternalUser(usr, "External"));

                        if (usr.UserId != 0)
                        {
                            // User Authentication handling
                            const string Issuer = "Noah Tong";
                            var          claims = new List <Claim>();
                            claims.Add(new Claim(ClaimTypes.Name, usr.FirstName + " " + usr.LastName, ClaimValueTypes.String, Issuer));
                            claims.Add(new Claim(ClaimTypes.Role, "Member", ClaimValueTypes.String, Issuer));
                            claims.Add(new Claim(ClaimTypes.UserData, usr.UserId.ToString(), ClaimValueTypes.Integer32, Issuer));
                            var userIdentity = new ClaimsIdentity("SecureLogin");
                            userIdentity.AddClaims(claims);
                            var userPrincipal = new ClaimsPrincipal(userIdentity);

                            await HttpContext.Authentication.SignInAsync("CookieMiddlewareInstance", userPrincipal,
                                                                         new AuthenticationProperties
                            {
                                IsPersistent = true,
                                AllowRefresh = false
                            });

                            return(RedirectToAction("LoginRed", "Redirect"));
                        }
                    }
                }

                throw new Exception("Account Synchronization failed. Please retry or contact us.");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#29
0
        private bool CheckMsg(MainConfig config, Message msg, out string error)
        {
            try
            {
                var    realMsg  = msg as MessageRegisterRequest;
                UIUser realUser = FindUser(config, realMsg.Account);
                if (null != realUser)
                {
                    throw new Exception("账号已存在");
                }
                var validateResult = new AccountValidationRule().Validate(realMsg.Account, null);
                if (validateResult.IsValid == false)
                {
                    throw new Exception(validateResult.ErrorContent.ToString());
                }

                validateResult = new PasswordValidationRule().Validate(realMsg.Password, null);
                if (validateResult.IsValid == false)
                {
                    throw new Exception(validateResult.ErrorContent.ToString());
                }

                validateResult = new NameValidationRule().Validate(realMsg.Name, null);
                if (validateResult.IsValid == false)
                {
                    throw new Exception(validateResult.ErrorContent.ToString());
                }

                validateResult = new IntroduceValidationRule().Validate(realMsg.Introduce, null);
                if (validateResult.IsValid == false)
                {
                    throw new Exception(validateResult.ErrorContent.ToString());
                }

                error = null;
                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
示例#30
0
        public UIUser InsertUser(UIUser user)
        {
            UIUser rtUser = null;

            this.Execute("INSERT INTO lianliankan_user(user_account, user_password, user_name, user_introduce, user_head_path) "
                         + $"VALUES('{user.Account}', '{user.Password}', '{user.Name}', '{user.Introduce}', '{user.HeadImageName}')", null);
            this.Execute($"SELECT * FROM lianliankan_user WHERE user_account = '{user.Account}'", async(reader) => {
                while (await reader.ReadAsync())
                {
                    rtUser = new UIUser((int)(reader["id"]),
                                        reader["user_account"].ToString(),
                                        reader["user_password"].ToString(),
                                        reader["user_name"].ToString());
                    rtUser.Introduce     = reader["user_introduce"].ToString();
                    rtUser.HeadImagePath = reader["user_head_path"].ToString();
                }
            });
            return(rtUser);
        }
示例#31
0
        public bool InitSession(UIUser.User userInfo)
        {
            //Check if data from last run still exists, if it does we remove it, it is now invalid

            string id = userInfo.Id.ToString();
            if (sessionInfo.ContainsKey(id))
                sessionInfo.Remove(id);

            SessionData data = new SessionData();
            data.UserInfo = userInfo;

            HttpContext.Current.Session.Add(SESSION_ID_TOKEN, id);
            sessionInfo.Add(id, data);

            return true;
        }