Ejemplo n.º 1
0
        private void RegisterUser(string wxopenid, string wxNickName, string clientIP, string userName, string nickName, string password, string alipayAccount, string alipayRealName, string IDCardNo, string email, string qq)
        {
            //invitationCode = Session["ic"] as string;
            string invitationCode = "";

            int result = WcfClient.Instance.RegisterUserFromWeiXin(wxopenid, wxNickName, clientIP, userName, nickName, password, alipayAccount, alipayRealName, IDCardNo, email, qq, invitationCode);

            if (result == OperResult.RESULTCODE_TRUE)
            {
                var player = WcfClient.Instance.GetPlayerByWeiXinOpenID(wxopenid);
                if (player != null)
                {
                    WebUserInfo userinfo = new WebUserInfo();
                    userinfo.xlUserID   = player.SimpleInfo.UserID;
                    userinfo.xlUserName = player.SimpleInfo.UserName;
                    userinfo.wxOpenID   = wxopenid;
                    // 登录状态100分钟内有效
                    MyFormsPrincipal <WebUserInfo> .SignIn(userinfo.xlUserName, userinfo, 100);

                    Session[userinfo.xlUserName] = player;
                }

                Response.Redirect("View/Index.aspx");
                //Response.Write("<script>alert('恭喜您成功加入灵币矿场!');this.location.href='View/Index.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('注册失败, 原因为:" + OperResult.GetMsg(result) + "')</script>");
            }
        }
Ejemplo n.º 2
0
        public CommonRtnEntity Register([FromBody] WebUserInfo info)
        {
            IWebUserServices services = new WebUserServices();

            int result = 0;

            //编辑
            if (info.ID > 0)
            {
                WebUserInfo oldUserInfo = services.QueryByID(info.ID);
                if (oldUserInfo != null)
                {
                    info.Pwd = oldUserInfo.Pwd;
                }
                info.LastLoginTime = DateTime.Now;
                services.Update(info);
                result = info.ID;
            }
            else
            {
                result = services.Add(info);
            }

            CommonRtnEntity rtnInfo = new CommonRtnEntity()
            {
                Success = result > 0,
                Data    = result,
                Message = result > 0 ? "注册成功!" : "注册失败!"
            };

            return(rtnInfo);
        }
Ejemplo n.º 3
0
        protected void btnEditUser_Click(object sender, EventArgs e)
        {
            ISession s = this.CurrentWebSession;

            using (ITransaction x = s.BeginTransaction())
            {
                WebUserInfo info = this.CurrentWebSession.CreateCriteria <WebUserInfo>()
                                   .Add(Restrictions.Eq("WebUserID", (Session["User"] as WebUser).ID))
                                   .UniqueResult <WebUserInfo>();

                if (info == null)
                {
                    throw new Exception("User info null");
                }

                info.FirstName      = txtFirstName.Text;
                info.LastName       = txtLastName.Text;
                info.PrimaryPhone   = txtPrimaryPhone.Text;
                info.SecondaryPhone = txtSecondaryPhone.Text;

                s.SaveOrUpdate(info);

                try {
                    x.Commit();
                }
                catch (Exception ex)
                {
                    x.Rollback();
                    throw ex;
                }
            }

            Response.Redirect("/UserProfile.aspx");
        }
Ejemplo n.º 4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren(ValidationConstraints.Enabled) == false)
            {
                return;
            }
            if (txtConfirmPassword.Text != txtPassword.Text)
            {
                DlgHelper.ShowAlertMsgBox("输入密码不一致,请重新输入!");
                return;
            }

            if (txtConfirmPassword.Text.Trim().Length < 6)
            {
                DlgHelper.ShowAlertMsgBox("密码长度最少是6位!");
                return;
            }

            if (cbxDepartment.SelectedValue == null)
            {
                DlgHelper.ShowAlertMsgBox("请选择部门!");
                return;
            }

            var userInfo = new WebUserInfo()
            {
                DepartmentID    = (int)cbxDepartment.SelectedValue,
                Adress          = txtAddress.Text.Trim(),
                ConfirmPassWord = txtConfirmPassword.Text.Trim(),
                PassWord        = txtPassword.Text.Trim(),
                Phone           = txtPhone.Text.Trim(),
                UserName        = txtUserName.Text.Trim(),
                IsMonitor       = ckBoxIsMonitor.Checked,
                IsPutinMan      = ckBoxIsPutinMan.Checked,
                IsRemovalMan    = ckBoxIsRemovalMan.Checked,
            };

            var result = new UserBLL().AddUser(userInfo);

            if (result.Code > 0)
            {
                DlgHelper.ShowAlertMsgBox(result.Msg);
                return;
            }
            else
            {
                DlgHelper.ShowAlertMsgBox("创建用户成功!");
                this.Close();
            }

            if (CallBack != null)
            {
                CallBack();
            }
        }
Ejemplo n.º 5
0
        public CommonRtnEntity Login([FromBody] WebUserInfo webUserInfo)
        {
            //throw new Exception("123");

            IWebUserServices webUserServices = new WebUserServices();

            string pwd = webUserInfo.Pwd;

            pwd = CommonUtitlity.CommonHelper.GetPwdCryptoStr(pwd);

            WebUserInfo       info    = webUserServices.Query(d => d.LoginName == webUserInfo.LoginName && d.Pwd == pwd).FirstOrDefault();
            Out_LoginUserInfo outUser = null;

            if (info != null)
            {
                info.LastLoginTime = DateTime.Now;
                info.LastLoginIP   = Accessor.HttpContext.Connection.RemoteIpAddress.ToString();

                webUserServices.Update(info);


                outUser = new Out_LoginUserInfo();

                outUser.ID   = info.ID;
                outUser.Name = info.Name;
                //outUser.Age = info.Age;
                outUser.LoginName = info.LoginName;
                outUser.ID        = info.ID;

                //如果是基于用户的授权策略,这里要添加用户;如果是基于角色的授权策略,这里要添加角色
                //var claims = new Claim[] { new Claim(ClaimTypes.Name, User.LoginName), new Claim(ClaimTypes.Role, "Sys"), new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString()) };
                ////用户标识
                //var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme);
                //identity.AddClaims(claims);

                TokenModel tokenModel = new TokenModel();
                tokenModel.Uid   = info.ID;
                tokenModel.Uname = info.LoginName;
                tokenModel.Sub   = "admin";


                outUser.Token = JwtToken.IssueJWT(tokenModel);
            }

            CommonRtnEntity rtnInfo = new CommonRtnEntity()
            {
                Success = outUser != null,
                Data    = outUser,
                Message = outUser != null ? "登录成功!" : "账号或者密码错误!"
            };

            return(rtnInfo);
        }
Ejemplo n.º 6
0
        public CResult <bool> AddUser(WebUserInfo webUser)
        {
            if (string.IsNullOrWhiteSpace(webUser.UserName))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                MembershipCreateStatus status;
                var user  = Membership.CreateUser(webUser.UserName, webUser.PassWord, null, null, null, true, out status);
                var roles = new List <string>();
                if (webUser.IsMonitor)
                {
                    roles.Add(PermissionEnum.班长.ToString());
                }
                if (webUser.IsPutinMan)
                {
                    roles.Add(PermissionEnum.入库员.ToString());
                }
                if (webUser.IsRemovalMan)
                {
                    roles.Add(PermissionEnum.出库员.ToString());
                }

                if (status == MembershipCreateStatus.Success)
                {
                    if (roles.Count() > 0)
                    {
                        Roles.AddUserToRoles(user.UserName, roles.ToArray());
                    }
                    var userInfo = new UsersInfo();
                    userInfo.ID           = (int)user.ProviderUserKey;
                    userInfo.Adress       = webUser.Adress;
                    userInfo.DepartmentID = webUser.DepartmentID;
                    userInfo.StateID      = (int)RecordState.Show;
                    userInfo.Phone        = webUser.Phone;
                    RepositoryIoc.GetUsersInfoRepository(db).Insert(userInfo);
                    if (db.SaveChanges() > 0)
                    {
                        return(new CResult <bool>(true));
                    }
                    else
                    {
                        return(new CResult <bool>(false, ErrorCode.AddUserInfoFailed));
                    }
                }
                else
                {
                    //Membership.DeleteUser(user.UserName, true);
                    return(new CResult <bool>(false, 1, status.ToString()));
                }
            }
        }
Ejemplo n.º 7
0
        public CommonRtnEntity FindPwd([FromBody] WebUserInfo info)
        {
            int result = 0;

            CommonRtnEntity rtnInfo = new CommonRtnEntity()
            {
                Success = result > 0,
                Data    = result,
                Message = result > 0 ? "添加成功!" : "添加失败!"
            };

            return(rtnInfo);
        }
Ejemplo n.º 8
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            WebUserInfo info = this.CurrentWebSession.CreateCriteria <WebUserInfo>()
                               .Add(Restrictions.Eq("WebUserID", (Session["User"] as WebUser).ID))
                               .UniqueResult <WebUserInfo>();

            txtEmailAddress.Text   = (Session["User"] as WebUser).EmailAddress;
            txtFirstName.Text      = info.FirstName;
            txtPrimaryPhone.Text   = info.PrimaryPhone;
            txtSecondaryPhone.Text = info.SecondaryPhone;
            txtLastName.Text       = info.LastName;
        }
Ejemplo n.º 9
0
        private static WebUserInfo ConverToWebUser(MembershipUser user, UsersInfo userInfo)
        {
            var webUserInfo  = new WebUserInfo();
            var currentRoles = Roles.GetRolesForUser(user.UserName);

            webUserInfo.Adress = userInfo.Adress;
            if (userInfo.Department != null)
            {
                webUserInfo.DepartmentName = userInfo.Department.DepartmentName;
            }
            webUserInfo.Phone        = userInfo.Phone;
            webUserInfo.UserName     = user.UserName;
            webUserInfo.ID           = (int)user.ProviderUserKey;
            webUserInfo.DepartmentID = userInfo.DepartmentID;
            webUserInfo.IsMonitor    = currentRoles.Contains(PermissionEnum.班长.ToString());
            webUserInfo.IsPutinMan   = currentRoles.Contains(PermissionEnum.入库员.ToString());
            webUserInfo.IsRemovalMan = currentRoles.Contains(PermissionEnum.出库员.ToString());
            return(webUserInfo);
        }
Ejemplo n.º 10
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            WebUserInfo info = this.CurrentWebSession.CreateCriteria <WebUserInfo>()
                               .Add(Restrictions.Eq("WebUserID", (Session["User"] as WebUser).ID))
                               .UniqueResult <WebUserInfo>();

            if (info == null)
            {
                throw new Exception("Info null");
            }

            lblEmailAddress.Text   = (Session["User"] as WebUser).EmailAddress;
            lblFirstName.Text      = info.FirstName;
            lblLastName.Text       = info.LastName;
            lblPrimaryPhone.Text   = info.PrimaryPhone;
            lblSecondaryPhone.Text = info.SecondaryPhone;
        }
Ejemplo n.º 11
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren(ValidationConstraints.Enabled) == false)
            {
                return;
            }

            if (_editOrView == true)
            {
                var userInfo = new WebUserInfo()
                {
                    ID           = _userID,
                    UserName     = txtUserName.Text.Trim(),
                    Adress       = txtAddress.Text.Trim(),
                    Phone        = txtPhone.Text.Trim(),
                    IsMonitor    = ckBoxIsMonitor.Checked,
                    IsRemovalMan = ckBoxIsRemovalMan.Checked,
                    IsPutinMan   = ckBoxIsPutinMan.Checked,
                };
                var result = new UserBLL().UpdateUser(userInfo);
                if (result.Code > 0)
                {
                    DlgHelper.ShowAlertMsgBox(result.Msg);
                    return;
                }
                else
                {
                    DlgHelper.ShowSuccessBox();
                    this.Close();
                    if (CallBack != null)
                    {
                        CallBack();
                    }
                }
            }
        }
Ejemplo n.º 12
0
        protected void btnLogin_Click(object sender, System.EventArgs e)
        {
            string hash = AutoAssess.Misc.Hashing.GetMd5Hash(txtPassword.Text, "sadf");

            WebUser user = this.CurrentWebSession.CreateCriteria <WebUser> ()
                           .Add(Restrictions.Eq("Username", txtUsername.Text))
                           .Add(Restrictions.Eq("PasswordHash", hash))
                           .Add(Restrictions.Eq("IsActive", true))
                           .List <WebUser>()
                           .FirstOrDefault();

            if (user == null)
            {
                lblLoginError.Text = "Invalid username/password combination.";
                txtUsername.Text   = string.Empty;
                txtPassword.Text   = string.Empty;
                return;
            }

            VerificationKey key = this.CurrentWebSession.CreateCriteria <VerificationKey>()
                                  .Add(Restrictions.Eq("WebUserID", user.ID))
                                  .UniqueResult <VerificationKey>();

            if (!key.IsVerifed)
            {
                lblLoginError.Text = "Please check your email for an account verification link.";
                txtUsername.Text   = string.Empty;
                txtPassword.Text   = string.Empty;
                return;
            }

            WebUserInfo info = this.CurrentWebSession.CreateCriteria <WebUserInfo>()
                               .Add(Restrictions.Eq("WebUserID", user.ID))
                               .UniqueResult <WebUserInfo>();

            info.LastLogin = DateTime.Now;

            using (ITransaction x = this.CurrentWebSession.BeginTransaction())
            {
                this.CurrentWebSession.SaveOrUpdate(info);

                try{
                    x.Commit();
                }
                catch (Exception ex)
                {
                    x.Rollback();
                    throw ex;
                }
            }

            Session["User"] = user;

            FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(1, user.UserID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), false, string.Empty /*Whatever data you want*/);
            string     cookiestr          = FormsAuthentication.Encrypt(tkt);
            HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);

            ck.Path = FormsAuthentication.FormsCookiePath;
            Response.Cookies.Add(ck);

            Response.Redirect("/Default.aspx", true);

            System.Security.Principal.GenericIdentity i = new System.Security.Principal.GenericIdentity(string.Empty, null);

            this.Context.User = new System.Security.Principal.GenericPrincipal(i, null);
        }
Ejemplo n.º 13
0
        public CResult <bool> UpdateUser(WebUserInfo webUser)
        {
            if (string.IsNullOrWhiteSpace(webUser.UserName))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                var user = Membership.GetUser(webUser.UserName);
                if (user == null)
                {
                    return(new CResult <bool>(false, ErrorCode.UserNoExist));
                }

                var roles       = new List <string>();
                var hasAddRoles = Roles.GetRolesForUser(webUser.UserName);
                if (webUser.IsMonitor)
                {
                    roles.Add(PermissionEnum.班长.ToString());
                }
                if (webUser.IsPutinMan)
                {
                    roles.Add(PermissionEnum.入库员.ToString());
                }
                if (webUser.IsRemovalMan)
                {
                    roles.Add(PermissionEnum.出库员.ToString());
                }
                var hasExistRoles = hasAddRoles.Intersect(roles);
                var toDelRoles    = hasAddRoles.Except(hasExistRoles);
                var toAddRoles    = roles.Except(hasExistRoles);
                if (toDelRoles.Count() > 0)
                {
                    Roles.RemoveUserFromRoles(webUser.UserName, toDelRoles.ToArray());
                }
                if (toAddRoles.Count() > 0)
                {
                    Roles.AddUserToRoles(webUser.UserName, toAddRoles.ToArray());
                }

                var userID     = (int)user.ProviderUserKey;
                var repository = RepositoryIoc.GetUsersInfoRepository(db);
                var userInfo   = repository.FirstOrDefault(r => r.ID == userID);
                if (userInfo == null)
                {
                    return(new CResult <bool>(false, ErrorCode.UserNoExist));
                }
                userInfo.Phone  = webUser.Phone;
                userInfo.Adress = webUser.Adress;
                if (repository.Update(userInfo) == EntityState.Modified)
                {
                    if (db.SaveChanges() > 0)
                    {
                        return(new CResult <bool>(true));
                    }
                    else
                    {
                        return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                    }
                }
                else
                {
                    return(new CResult <bool>(true));
                }
            }
        }
Ejemplo n.º 14
0
    void OnGUI()
    {
        if (_bMsgbox)
        {
            GUI.Box(new Rect(Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2), _szMsg);
            if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height - Screen.height / 4, 100, 50), "OK"))
            {
                _bMsgbox    = false;
                GUI.enabled = true;
            }
            GUI.enabled = false;
        }
        else
        {
            GUI.enabled = !_bBlockinput;
        }

        GUI.Box(new Rect(10, 10, 150, 180), "Loader Menu");
        {
            if (GUI.Button(new Rect(20, 40, 130, 20), "회원가입"))
            {
                // MonoBehaviour를 상속받지 않은 일반 클래스
                // C#의 모든 객체는 동적할당해야 사용 가능. 할당된 객체는 Garbage Collector에 의해 자동으로 파괴
                WebRegister Reg = new WebRegister();

                Reg.id       = this.id;
                Reg.password = this.password;

                // 내부에서 코루틴 함수 호출
                NetWWW.INSTANCE().Send(Reg, true);
                // TODO: !!주의!! 유니티 코루틴 사용 시 참고 사항
                // 이 부분에서 STartCoroutine()을 직접 호출해선 안됨.
                // 1. 코루틴 종료가 늦어지거나 설계상의 문제로 종료되지 않을 경우, 메모리 정리를 하지 않기 때문에 가끔씩 튐
                // 2. 양적으로 많아지면 매 프레임마다 다 들려야 하므로 느려짐
                // -> 라이브에서는 해당 예제처럼 객체들을 각각의 패킷으로 여기고 직렬화하여 직렬화하여 순차적으로 전송해야함 (디자인 패턴 중 Command Pattern 참고)
            }
            if (GUI.Button(new Rect(20, 40 + 30, 130, 20), "로그인"))
            {
                WebLogin Login = new WebLogin();

                Login.id       = this.id;
                Login.password = this.password;

                NetWWW.INSTANCE().Send(Login, true);
            }
            if (GUI.Button(new Rect(20, 40 + 60, 130, 20), "유저 정보"))
            {
                WebUserInfo Info = new WebUserInfo();

                Info.accountno = this.accountno;
                Info.session   = this.session;

                NetWWW.INSTANCE().Send(Info, true);
            }

            if (GUI.Button(new Rect(20, 40 + 90, 130, 20), "세션 갱신"))
            {
                WebSession Session = new WebSession();

                Session.accountno = this.accountno;
                Session.session   = this.session;

                NetWWW.INSTANCE().Send(Session, true);
            }

            if (GUI.Button(new Rect(20, 40 + 120, 130, 20), "스테이지 클리어"))
            {
                WebStageClear Clear = new WebStageClear();

                Clear.accountno = this.accountno;
                Clear.session   = this.session;
                Clear.stageid   = this.stageid;

                NetWWW.INSTANCE().Send(Clear, true);
            }
        }

        GUI.enabled = true;
    }
Ejemplo n.º 15
0
 public ImageService(IImageRepository imageRepository, WebUserInfo userInfo)
 {
     ImageRepository = imageRepository;
     UserInfo        = userInfo;
 }
Ejemplo n.º 16
0
        protected void btnBind_Click(object sender, EventArgs e)
        {
            try
            {
                string userName = this.txtUserName.Text.Trim();
                string password = this.txtPassword.Text;
                if (userName == "")
                {
                    Response.Write("<script>alert('请输入用户名')</script>");
                    return;
                }
                if (password == "")
                {
                    Response.Write("<script>alert('请输入密码')</script>");
                    return;
                }
#if Test
                WeiXinUserInfoModel userObj = null;

                if (userName == "小开心")
                {
                    userObj = new WeiXinUserInfoModel()
                    {
                        openid   = Config.TestUserOpenId,
                        nickname = "小查",
                    };
                }
                else if (userName == "nero")
                {
                    userObj = new WeiXinUserInfoModel()
                    {
                        openid   = Config.TestLVSU_UserOpenID,
                        nickname = "wgflicker",
                    };
                }

                Session[Config.SESSIONKEY_WXUSERINFO] = userObj;
                string ip = System.Web.HttpContext.Current.Request.UserHostAddress;

                OperResultObject resultObj = WcfClient.Instance.WeiXinLogin(userObj.openid, userObj.nickname, ip);

                if (resultObj.OperResultCode == OperResult.RESULTCODE_TRUE)
                {
                    var player = WcfClient.Instance.GetPlayerByWeiXinOpenID(userObj.openid);

                    WebUserInfo userinfo = new WebUserInfo();
                    userinfo.xlUserID   = player.SimpleInfo.UserID;
                    userinfo.xlUserName = player.SimpleInfo.UserName;
                    userinfo.wxOpenID   = userObj.openid;

                    // 登录状态100分钟内有效
                    MyFormsPrincipal <WebUserInfo> .SignIn(userinfo.xlUserName, userinfo, 100);

                    Session[userinfo.xlUserName] = player;

                    Response.Redirect("View/Index.aspx", false);
                    //Server.Execute("View/Index.aspx");
                }
                else if (resultObj.OperResultCode == OperResult.RESULTCODE_EXCEPTION)
                {
                    Response.Write("<script>alert('服务器连接失败,请稍候再试')</script>");
                }
                else
                {
                    string message = string.IsNullOrEmpty(resultObj.Message) ? OperResult.GetMsg(resultObj.OperResultCode) : resultObj.Message;
                    Response.Write("<script>alert('测试登录失败, 原因为:" + message + "')</script>");
                }
#else
                WeiXinUserInfoModel wxuserinfo = Session["wxuserinfo"] as WeiXinUserInfoModel;
                if (wxuserinfo == null)
                {
                    Response.Write("<script>alert('只能从微信客户端打开')</script>");
                    return;
                }

                if (string.IsNullOrEmpty(wxuserinfo.openid))
                {
                    Response.Write("<script>alert('微信登录失败,无法绑定')</script>");
                    return;
                }


                string ip = System.Web.HttpContext.Current.Request.UserHostAddress;

                OperResultObject resultObj = WcfClient.Instance.BindWeiXinUser(wxuserinfo.openid, wxuserinfo.nickname, userName, password, ip);
                if (resultObj.OperResultCode == OperResult.RESULTCODE_TRUE)
                {
                    var player = WcfClient.Instance.GetPlayerByWeiXinOpenID(wxuserinfo.openid);
                    if (player != null)
                    {
                        WebUserInfo userinfo = new WebUserInfo();
                        userinfo.xlUserID   = player.SimpleInfo.UserID;
                        userinfo.xlUserName = player.SimpleInfo.UserName;
                        userinfo.wxOpenID   = wxuserinfo.openid;
                        // 登录状态100分钟内有效
                        MyFormsPrincipal <WebUserInfo> .SignIn(userinfo.xlUserName, userinfo, 100);

                        Session[userinfo.xlUserName] = player;

                        Response.Redirect("View/Index.aspx", false);
                    }
                    else
                    {
                        Response.Write("<script>alert('绑定失败, 原因为:没有找到迅灵账户')</script>");
                    }
                }
                else
                {
                    string message = string.IsNullOrEmpty(resultObj.Message) ? OperResult.GetMsg(resultObj.OperResultCode) : resultObj.Message;
                    Response.Write("<script>alert('绑定失败, 原因为:" + message + "')</script>");
                }
#endif
            }
            catch (Exception exc)
            {
                LogHelper.Instance.AddErrorLog("Bind User Exception", exc);
            }
        }
Ejemplo n.º 17
0
 public UserService(IUserRepository userRepository, WebUserInfo userInfo)
 {
     UserRepository = userRepository;
     UserInfo       = userInfo;
 }
Ejemplo n.º 18
0
        protected void btnCreateUser_Click(object sender, EventArgs e)
        {
            ISession s = this.CurrentWebSession;

            using (ITransaction t = s.BeginTransaction())
            {
                DateTime now = DateTime.Now;

                WebUser user = new WebUser();
                user.Username     = txtUsername.Text;
                user.EmailAddress = txtEmailAddress.Text;
                user.UserID       = Guid.NewGuid();
                user.IsActive     = true;
                //user.CreatedBy = this.CurrentUser.UserID;
                //user.CreatedOn = DateTime.UtcNow;

                WebUserInfo info = new WebUserInfo();
                info.WebUser             = user;
                info.FirstName           = txtFirstName.Text;
                info.ID                  = Guid.NewGuid();
                info.LastName            = txtLastName.Text;
                info.LastLogin           = DateTime.Now;
                info.PrimaryPhone        = txtPrimaryPhone.Text;
                info.SecondaryPhone      = txtSecondaryPhone.Text;
                info.Hosts               = int.Parse(ddlNumberOfHosts.SelectedValue);
                info.MainSecurityConcern = ddlMainConcern.SelectedValue;
                info.Provider            = ddlProvider.SelectedValue;
                info.PrimaryWebsite      = txtPrimaryWebsite.Text;
                info.IsActive            = true;

                string hash = Hashing.GetMd5Hash(txtPassword.Text, "sadf");

                user.PasswordHash = hash;

                VerificationKey vkey = new VerificationKey();
                vkey.ID             = Guid.NewGuid();
                vkey.Key            = Guid.NewGuid();
                vkey.IsActive       = true;
                vkey.CreatedBy      = Guid.Empty;
                vkey.CreatedOn      = now;
                vkey.LastModifiedBy = Guid.Empty;
                vkey.LastModifiedOn = now;
                vkey.IsVerifed      = false;
                vkey.IsSent         = true;         //sending below
                vkey.User           = user;

                s.SaveOrUpdate(vkey);
                s.SaveOrUpdate(info);
                s.SaveOrUpdate(user);

                try
                {
                    t.Commit();
                }
                catch (Exception ex)
                {
                    t.Rollback();
                    throw ex;
                }

                SendVerificationEmail(info.FirstName + " " + info.LastName, user.EmailAddress, user.ID.ToString(), vkey.Key.ToString());

                Response.Redirect("Login.aspx");
            }
        }
Ejemplo n.º 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.IsPostBack)
                {
                    //code说明 : code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。
                    string code  = Request["code"];
                    string state = Request["state"];

                    this.lblMsg.Text = "欢迎进入迅灵矿场";

                    LogHelper.Instance.AddInfoLog("code:" + code + "; state: " + state);

                    if (state == Config.state)
                    {
                        HttpGetReturnModel resultValue = WeiXinHandler.SynGetUserAccessToken(code);
                        if (resultValue.Exception != null)
                        {
                            this.lblMsg.Text = "登录异常,请联系迅灵矿场管理员";
                            return;
                        }

                        if (resultValue.ResponseError != null)
                        {
                            Session[Config.SESSIONKEY_RESPONSEERROR] = resultValue.ResponseError;
                            Server.Transfer("ErrorPage.aspx");
                            return;
                        }

                        AuthorizeResponseModel authObj = resultValue.ResponseResult as AuthorizeResponseModel;
                        if (authObj != null)
                        {
                            this.lblMsg.Text = "authObj OK";
                            Session[Config.SESSIONKEY_AUTHORIZEOBJ] = authObj;
                            resultValue = WeiXinHandler.SyncGetUserInfo(authObj.access_token, authObj.openid);
                        }
                        if (resultValue.Exception != null)
                        {
                            this.lblMsg.Text = "登录异常,请联系迅灵矿场管理员";
                            return;
                        }

                        if (resultValue.ResponseError != null)
                        {
                            Session[Config.SESSIONKEY_RESPONSEERROR] = resultValue.ResponseError;
                            Server.Transfer("ErrorPage.aspx");
                            return;
                        }

                        WeiXinUserInfoModel userObj = resultValue.ResponseResult as WeiXinUserInfoModel;
                        Session[Config.SESSIONKEY_WXUSERINFO] = userObj;
                        string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
                        this.lblMsg.Text = "欢迎  " + userObj.nickname + "  进入迅灵矿场";

                        OperResultObject resultobj = WcfClient.Instance.WeiXinLogin(userObj.openid, userObj.nickname, ip);

                        this.lblMsg.Text = "登录迅灵矿场,结果为:" + OperResult.GetMsg(resultobj.OperResultCode);
                        if (resultobj.OperResultCode == OperResult.RESULTCODE_TRUE)
                        {
                            this.lblMsg.Text = "WeiXinLogin OK";
                            var player = WcfClient.Instance.GetPlayerByWeiXinOpenID(userObj.openid);

                            this.lblMsg.Text = "player OK";
                            WebUserInfo userinfo = new WebUserInfo();
                            userinfo.xlUserID   = player.SimpleInfo.UserID;
                            userinfo.xlUserName = player.SimpleInfo.UserName;
                            userinfo.wxOpenID   = userObj.openid;

                            // 登录状态100分钟内有效
                            MyFormsPrincipal <WebUserInfo> .SignIn(userinfo.xlUserName, userinfo, 100);

                            //Session[userinfo.xlUserName] = player;

                            Response.Redirect("View/Index.aspx", false);
                        }
                        else if (resultobj.OperResultCode == OperResult.RESULTCODE_USER_NOT_EXIST || resultobj.OperResultCode == OperResult.RESULTCODE_USERNAME_PASSWORD_ERROR)
                        {
                            Response.Redirect("LoginPage.aspx", false);
                        }
                        else
                        {
                            string message = string.IsNullOrEmpty(resultobj.Message) ? OperResult.GetMsg(resultobj.OperResultCode) : resultobj.Message;
                            Response.Write("<script>alert('登录迅灵矿场失败, 原因为:" + message + "')</script>");
                        }
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception exc)
            {
                this.lblMsg.Text = "WeiXinResponse Exception. " + exc.Message;
                LogHelper.Instance.AddErrorLog("WeiXinResponse Exception", exc);
            }
        }