Example #1
0
        protected void uploadAvatar_Click(object sender, EventArgs e)
        {
            int maxSizeFile = 1024 * 1024 * 4;

            if (avatar.FileContent.Length > maxSizeFile)
            {
                errorUpload.Text = "The upload avatar must be less than 4mb !";
            }
            else if (checkType(Path.GetExtension(avatar.FileName)) == false)
            {
                errorUpload.Text = "The upload avatar must be an image !";
            }
            else if (Session["currentUser"] != null)
            {
                User user = (User)Session["currentUser"];
                UserService.UserService userservice = new UserService.UserService();

                BinaryReader br    = new BinaryReader(avatar.PostedFile.InputStream);
                byte[]       bytes = br.ReadBytes((int)avatar.PostedFile.InputStream.Length);

                string filename = string.Format("{0}{1}", user.userName, Path.GetExtension(avatar.FileName));
                userservice.updateAvatar(Server.MapPath("~"), filename, user.id, bytes);
                Page.Response.Redirect(Page.Request.Url.ToString(), true);
            }
        }
Example #2
0
        protected void submit_Click(object sender, EventArgs e)
        {
            UserService.UserService service = new UserService.UserService();
            UserService.User        user    = service.checkLogin(Request.Form["usernameTxt"], Request.Form["passwordTxt"]);

            if (user == null)
            {
                errorTxt.Text = "Username or Password is incorrect";
            }
            else
            {
                errorTxt.Text = user.fullName;
                Session.Add("currentUser", user);
                Session.Add("username", user.userName);
                Response.Redirect("Home.aspx");
            }
        }
Example #3
0
        protected void changeBtn_Click(object sender, EventArgs e)
        {
            User user = (User)Session["currentUser"];

            UserService.UserService userservice = new UserService.UserService();

            string oldPassword = Request.Form["oldPassword"];
            string newPasswrod = Request.Form["password"];

            if (userservice.changePassword(user.id, oldPassword, newPasswrod))
            {
                Response.Redirect("Profile.aspx");
            }
            else
            {
                errorTxt.Text = "Old password is incorrect ! Try again !";
            }
        }
Example #4
0
        protected void submit_Click(object sender, EventArgs e)
        {
            UserService.UserService service = new UserService.UserService();
            string   username    = Request.Form["username"];
            string   email       = Request.Form["email"];
            string   fullname    = Request.Form["fullname"];
            string   password    = Request.Form["password"];
            DateTime birthOfDate = DateTime.ParseExact(Request.Form["birthOfDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture);
            string   message     = service.register(username, email, fullname, password, birthOfDate);

            if (message != null)
            {
                errorTxt.Text = message;
            }
            else
            {
                Server.Transfer("Login.aspx");
            }
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // set title for page
            Page.Title = "Profile - BookShare";

            int idUser = 0;

            if (Request.QueryString["id"] == null)
            {
                if (checkCurrentUser() != 0)
                {
                    idUser   = checkCurrentUser();
                    readOnly = false;
                }
            }
            else
            {
                int.TryParse(Request.QueryString["id"], out idUser);
                readOnly = checkCurrentUser() == idUser ? false : true;
            }

            UserService.UserService userservice = new UserService.UserService();
            viewUser = userservice.getUserById(idUser);
        }