コード例 #1
0
ファイル: Home.aspx.cs プロジェクト: nutrimax1987/TRIVIA
 private void Login(string email, string pass)
 {
     _jsonHelper = new JsonHelper<object>();
     _cometProcessor = new CometClientProcessor();
     _playerService = new PlayerService();
     Player player = new Player();
     player.password = pass;
     player.email = email;
     _playerService = new PlayerService();
     if (_playerService.Verify(player))
     {
         player = _playerService.FindByEmail(LoginEmail.Text);
         // Create  Cookie
         HttpCookie time = new HttpCookie("LastLogined", DateTime.Now.ToString());
         HttpCookie userEmail = new HttpCookie("userEMail", player.email);
         HttpCookie userId = new HttpCookie("userId", player.id.ToString());
         time.Expires = DateTime.Now.AddDays(1);
         userEmail.Expires = DateTime.Now.AddDays(1);
         HttpContext.Current.Response.Cookies.Add(time);
         HttpContext.Current.Response.Cookies.Add(userEmail);
         HttpContext.Current.Response.Cookies.Add(userId);
         HttpContext.Current.Session["Email"] = player.email;
         HttpContext.Current.Session["Username"] = player.username;
         Response.Redirect("Games.aspx"); //if true - so code after this not working - its abort the thread
     }
     else
     {
         string message = "<div class='alert alert-warning'>This email and password not found,Please register or try again</div>";
         Alert.Text = message;
     }
 }
コード例 #2
0
ファイル: Home.aspx.cs プロジェクト: nutrimax1987/TRIVIA
        protected void Register_Click(object sender, EventArgs e)
        {
            uidForImage = Guid.NewGuid();
            string fileName = System.IO.Path.GetFileName(PictureUpload.PostedFile.FileName);
            _playerService = new PlayerService();
            _jsonHelper = new JsonHelper<Object>();
            Player newPlayer = new Player();
            newPlayer.username = RegisterUsername.Text;
            newPlayer.email = RegisterEmail.Text;
            // kod zashivrovali v settere
            newPlayer.password = RegisterPassword.Text;
            newPlayer.image = uidForImage + fileName;
            newPlayer.registration_date = DateTime.Now;

            if (!_playerService.CheckIfExists(newPlayer))
            {
                // do stuff here to log the user in ...
                if (_playerService.Insert(newPlayer))
                {
                    UploadImage(sender, e);
                    Login(newPlayer.email, newPlayer.password);
                }
            }
            else
            {
                string message = "<div class='alert alert-warning'>This email is registered,Please login or register another one</div>";
                Alert.Text = message;
                Response.Redirect("Home.aspx");
            }
        }