Example #1
0
        private void Login_Click(object sender, EventArgs e)
        {
            CancelEventArgs cea = new CancelEventArgs();

            userName_Validating(sender, cea);
            password_Validating(sender, cea);

            if (cea.Cancel == false)
            {
                UserService.UserServiceClient usermanage = new UserService.UserServiceClient();
                try
                {
                    MD5CryptoServiceProvider Md5 = new MD5CryptoServiceProvider();
                    byte[] passwordBytes         = Encoding.UTF8.GetBytes(this.txtPassword.Text);
                    byte[] hashCode        = Md5.ComputeHash(passwordBytes);
                    string encryptPassword = BitConverter.ToString(hashCode).Replace(LINE, Constants.emptyStr);
                    bool   result          = usermanage.VerifyUserLogin(this.txtUsername.Text, encryptPassword);

                    if (result == true)
                    {
                        RememberSomeParameter.username = this.txtUsername.Text;
                        RememberSomeParameter.userId   = Convert.ToInt32(usermanage.queryUserIdByName(this.txtUsername.Text));
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.lblPassErrorMessage.Visible = true;
                        this.lblErrorMessage.Text        = NOT_CORRECT_PASS;
                        this.lblErrorMessage.Visible     = true;
                    }
                }
                catch (FaultException <UserNameNotExistent> )
                {
                    this.lblUsernameErrorMessage.Visible = true;
                    this.lblErrorMessage.Text            = USER_NAME_NOT_EXIST;
                    this.lblErrorMessage.Visible         = true;
                }
                catch (CommunicationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (Exception exx)
                {
                    Console.WriteLine(exx.Message);
                }
            }
        }
Example #2
0
 //change avatar
 private void BtnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         if (!this.ofd.FileName.Equals(string.Empty))
         {
             MemoryStream ms = new MemoryStream();
             this.pbShowPhoto.Image.Save(ms, ImageFormat.Jpeg);
             ms.Position = 0;
             UserService.UserServiceClient userManager = new UserService.UserServiceClient();
             userManager.UpdatePhoto(RememberUserParameter.userId, ms.ToArray());
             this.pbuserPhoto.Image = Image.FromFile(this.ofd.FileName);
             this.pnlPhoto.Hide();
         }
     }
     catch (Exception ex)
     {
         Log4NetHelper.WriteErrorLog(typeof(UserProfileForm), ex);
     }
 }
Example #3
0
        public UserProfileForm()
        {
            InitializeComponent();

            if (FormPassValue.whichRole == Constants.Teacher_Role)
            {
                this.lblHome.Hide();
                this.lblMyExam.Hide();
                this.lblExamList.Show();
            }

            //set language environment
            Thread.CurrentThread.CurrentCulture = new CultureInfo(FormPassValue.languageState);
            SetResourceCulture();

            if (Process.GetCurrentProcess().ProcessName != "devenv")
            {
                userManager = new UserService.UserServiceClient();
                var table = userManager.GetUserInformation(RememberUserParameter.userId);

                foreach (var item in table)
                {
                    this.lblUsernameValue.Text    = item.UserName;
                    this.lblChineseNameValue.Text = item.ChineseName;
                    this.lblGenderValue.Text      = item.Gender;
                    this.lblIdValue.Text          = item.ID.ToString();
                    this.lblRoleValue.Text        = item.RoleType;
                    this.lblTelephoneValue.Text   = item.TelephoneNumber;
                    this.lblEmailValue.Text       = item.EMail;
                    if (item.IsPicNull() == false)
                    {
                        byte[]       pic = item.Pic;
                        MemoryStream ms  = new MemoryStream(pic);
                        this.pbuserPhoto.Image = Image.FromStream(ms);
                        this.pbShowPhoto.Image = Image.FromStream(ms);
                    }
                }
            }
        }
Example #4
0
        private void Login_Click(object sender, EventArgs e)
        {
            CancelEventArgs cea = new CancelEventArgs();

            UserName_Validating(sender, cea);
            Password_Validating(sender, cea);

            if (cea.Cancel == false)
            {
                UserService.UserServiceClient userManager = new UserService.UserServiceClient();
                try
                {
                    string encryptPassword = EncryptUtils.EncryptPassword(this.txtPassword.Text);
                    bool   result          = userManager.VerifyUserLogin(this.txtUsername.Text.Trim(), encryptPassword);

                    if (result == true)
                    {
                        RememberUserParameter.username = this.txtUsername.Text.Trim();
                        RememberUserParameter.userId   = Convert.ToInt32(userManager.QueryUserIdByName(this.txtUsername.Text.Trim()));

                        //remember password
                        if (this.lblSelect.Visible)
                        {
                            UserInfo user = new UserInfo();
                            user.UserName = this.txtUsername.Text.Trim();
                            user.Password = this.txtPassword.Text.Trim();
                            FileStream      fs = new FileStream(passwordFilePath, FileMode.Create);
                            BinaryFormatter bf = new BinaryFormatter();
                            bf.Serialize(fs, user);
                            fs.Close();
                        }
                        else
                        {
                            FileStream fs = new FileStream(passwordFilePath, FileMode.Open, FileAccess.Write);
                            if (fs.Length > 0)
                            {
                                fs.SetLength(0);
                                fs.Close();
                            }
                        }

                        Log4NetHelper.WriteInfoLog(typeof(LoginForm), "Login successfully!");
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.lblPassErrorMessage.Visible = true;
                        this.lblErrorMessage.Text        = ResourceCulture.GetString(NOT_CORRECT_PASS);
                        this.lblErrorMessage.Visible     = true;
                        Log4NetHelper.WriteInfoLog(typeof(LoginForm), "Password error!");
                    }
                }
                catch (FaultException <UserNameNotExistent> )
                {
                    this.lblUsernameErrorMessage.Visible = true;
                    this.lblErrorMessage.Text            = ResourceCulture.GetString(USER_NAME_NOT_EXIST);
                    this.lblErrorMessage.Visible         = true;
                    Log4NetHelper.WriteInfoLog(typeof(LoginForm), "User isn't existent!");
                }
                catch (CommunicationException ex)
                {
                    Log4NetHelper.WriteErrorLog(typeof(LoginForm), ex);
                }
                catch (Exception exx)
                {
                    Log4NetHelper.WriteErrorLog(typeof(LoginForm), exx);
                }
            }
        }
Example #5
0
 public bool IsTeacher()
 {
     UserService.UserServiceClient userManager = new UserService.UserServiceClient();
     return(userManager.VerifyIsTeacher(RememberUserParameter.userId));
 }