public ActionResult EditPassword(int id)
        {
            UserU emsUserU = new UserU();

            emsUserU = clsuser.GetUserById(id);
            return(View(emsUserU));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int x = 6;
            int y = 8;

            y = y + x;
            int z;

            if (x > y)
            {
                z = x + y;
            }
            UserU u1 = new UserU()
            {
                age = 20, fio = "Иванов"
            };
            UserU u2 = new UserU()
            {
                age = 18, fio = "Петров"
            };
            UserU u3;

            u3  = u1 + u2;
            u3  = u1 + 8;
            u3 += 6;
            u3 += u1;

            z = u3;
        }
Beispiel #3
0
        public string changeUserPassword(int ID, UserU emsUser)
        {
            var idendity = (HttpContext.Current.User as clsPrincipal).Identity as clsIdentity;

            p = new SqlParameter[4];

            try
            {
                p[0]           = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                p[0].Value     = emsUser.Password;
                p[1]           = new SqlParameter("@ID", SqlDbType.Int, 0);
                p[1].Value     = ID;
                p[2]           = new SqlParameter("@TrnUser", SqlDbType.VarChar, 50);
                p[2].Value     = idendity.User.Username;
                p[3]           = new SqlParameter("@msg", SqlDbType.VarChar, 50);
                p[3].Direction = ParameterDirection.Output;

                SqlHelper.ExecuteNonQuery(clsConnectionString.getConnectionString(), CommandType.StoredProcedure, "spUserChangePassword", p);
                return(p[8].Value.ToString());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Beispiel #4
0
        public string createUser(UserU emsUser)
        {
            var idendity = (HttpContext.Current.User as clsPrincipal).Identity as clsIdentity;

            p = new SqlParameter[6];

            try
            {
                p[0]           = new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 50);
                p[0].Value     = emsUser.EmployeeCode;
                p[1]           = new SqlParameter("@Username", SqlDbType.VarChar, 50);
                p[1].Value     = emsUser.Username;
                p[2]           = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                p[2].Value     = emsUser.Password;
                p[3]           = new SqlParameter("@TrnUser", SqlDbType.VarChar, 50);
                p[3].Value     = idendity.User.Username;
                p[4]           = new SqlParameter("@Active", SqlDbType.Bit, 0);
                p[4].Value     = emsUser.Active;
                p[5]           = new SqlParameter("@msg", SqlDbType.VarChar, 50);
                p[5].Direction = ParameterDirection.Output;

                SqlHelper.ExecuteNonQuery(clsConnectionString.getConnectionString(), CommandType.StoredProcedure, "spUserCrate", p);
                return(p[5].Value.ToString());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        public ActionResult Login(LogIn login, string returnUrl = "")
        {
            if (ModelState.IsValid)
            {
                bool isValidUser = Membership.ValidateUser(login.Username, login.Password);
                if (isValidUser)
                {
                    UserU UserU = null;
                    UserU = clsU_User.GetUserByUsername(login.Username);

                    if (User != null)
                    {
                        JavaScriptSerializer js = new JavaScriptSerializer();
                        string data             = js.Serialize(UserU);

                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserU.Username, DateTime.Now, DateTime.Now.AddMinutes(30), false, data);
                        string encToken = FormsAuthentication.Encrypt(ticket);

                        HttpCookie authCookies = new HttpCookie(FormsAuthentication.FormsCookieName, encToken);
                        Response.Cookies.Add(authCookies);
                        //return Redirect(returnUrl);
                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }
            }

            return(View());
        }
Beispiel #6
0
            /* public static UserU operator +(UserU x, int y)
             * {
             *   x.age += y;
             *   return x;
             * }*/
            public static UserU operator +(UserU x, int y)
            {
                UserU tempOb = new UserU();

                tempOb.fio = "not defined";
                tempOb.age = x.age + y;
                return(tempOb);
            }
Beispiel #7
0
            public static UserU operator +(UserU x, UserU y)
            {
                UserU tempOb = new UserU();

                tempOb.fio = "not defined";
                tempOb.age = (x.age + y.age) / 2;
                return(tempOb);
            }
        public ActionResult EditPassword(int id, UserU users)
        {
            try
            {
                clsuser.changeUserPassword(id, users);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(UserU users)
        {
            try
            {
                clsuser.createUser(users);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
        public override bool ValidateUser(string username, string password)
        {
            UserU _emsUserU = clsU_User.GetUserByUsername(username);

            if (_emsUserU.Username == username && _emsUserU.Password == password)
            {
                //ViewBag.UserFirstName = _emsUserU.FirstName;

                return(true);
            }

            return(false);
        }
Beispiel #11
0
        protected void Application_PostAuthenticateRequest()
        {
            HttpCookie authoCookies = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authoCookies != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authoCookies.Value);

                if (ticket != null && !ticket.Expired)
                {
                    JavaScriptSerializer js   = new JavaScriptSerializer();
                    UserU        user         = js.Deserialize <UserU>(ticket.UserData);
                    clsIdentity  clsIdentity  = new clsIdentity(user);
                    clsPrincipal clsPrincipal = new clsPrincipal(clsIdentity);
                    HttpContext.Current.User = clsPrincipal;
                }
            }
        }
Beispiel #12
0
        public UserU GetUserByUsername(string Username)
        {
            p = new SqlParameter[1];

            try
            {
                p[0]       = new SqlParameter("@Username", SqlDbType.VarChar, 50);
                p[0].Value = Username;

                using (SqlDataReader dr = SqlHelper.ExecuteReader(clsConnectionString.getConnectionString(), CommandType.StoredProcedure, "spSelectUserFromUsername", p))
                {
                    UserU user = new UserU();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            user.Id               = int.Parse(dr["ID"].ToString());
                            user.EmployeeCode     = dr["EmployeeCode"].ToString();
                            user.EmployeeCategory = dr["EmployeeCategoryName"].ToString();
                            user.Username         = dr["Username"].ToString();
                            user.NickName         = dr["NickName"].ToString();
                            user.Password         = dr["Password"].ToString();
                            user.FirstName        = dr["FirstName"].ToString();
                            user.LastName         = dr["LastName"].ToString();
                            user.Email            = dr["Email"].ToString();
                            user.TrnDate          = DateTime.Parse(dr["TrnDate"].ToString());
                            user.TrnUser          = dr["TrnUser"].ToString();
                            user.Active           = bool.Parse(dr["Active"].ToString());
                        }
                    }
                    return(user);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #13
0
 public clsIdentity(UserU user)
 {
     Identity = new GenericIdentity(user.Username);
     User     = user;
 }