Beispiel #1
0
        public ActionResult ChangePassword(String password)
        {
            var employeeId = Int64.Parse(Session["employeeId"].ToString());

            keys _keys = new keys();

            data.AES aes = new data.AES();
            var      key = _keys.GetOneById(1);

            users _users = new users();
            var   user   = _users.GetOneByEmployeeId(employeeId);

            user.userPassword = aes.Encriptar(password, key.C_Key, key.C_IV);

            //I need a second BS user for update
            users _users02 = new users();

            try
            {
                _users02.Update(user);
                return(Json(new { sucess = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #2
0
        public ActionResult SingIn(String userName, String password)
        {
            keys _keys = new keys();

            data.AES aes = new data.AES();

            var key = _keys.GetOneById(1);

            var employee = _employees.SingIn(aes.Encriptar(userName, key.C_Key, key.C_IV), aes.Encriptar(password, key.C_Key, key.C_IV));

            if (employee != null)
            {
                //save employee ID in Session
                HttpContext.Session.Add("employeeId", employee.employeeId);

                users_x_rols _users_x_rols = new users_x_rols();
                //find rols by user id
                byte[] rols = _users_x_rols.GetAllByUserId(employee.users.FirstOrDefault().userId).Select(x => x.rolId).ToArray();

                //save rols in Session
                HttpContext.Session.Add("rols", rols);

                return(Json(new { rols }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public ActionResult Register(data.employee employee, String countryCode, Boolean isAdmin, Boolean isSeller)
        {
            employee.phone        = "+" + countryCode + employee.phone;
            employee.registerDate = DateTime.Now;
            employee.isActive     = true;
            _employees.Insert(employee);

            #region user
            //import AES
            data.AES aes = new data.AES();

            //get keys for encrypt
            keys     _keys = new keys();
            data.key key   = new data.key();
            key = _keys.GetOneById(1);

            //create and encrypt user
            data.user user  = new data.user();
            users     _user = new users();

            var    dateTime = DateTime.Now;
            String userName = CreatePassword(3) + dateTime.Day + dateTime.Month + dateTime.Second;
            String password = CreatePassword(6);
            user.employeeId   = _employees.GetLastOrDefault().employeeId;
            user.userName     = aes.Encriptar(userName, key.C_Key, key.C_IV);
            user.userPassword = aes.Encriptar(password, key.C_Key, key.C_IV);
            user.expireDate   = DateTime.Now.AddDays(1);
            _user.Insert(user);

            //add rols
            data.user_x_rols user_x_rols   = new data.user_x_rols();
            users_x_rols     _users_x_rols = new users_x_rols();

            user_x_rols.userId = _user.GetLastOrDefault().userId;
            for (int i = 0; i < 2; i++)
            {
                if (isAdmin)
                {
                    isAdmin           = false;
                    user_x_rols.rolId = 1;
                    _users_x_rols.Insert(user_x_rols);
                }
                else if (isSeller)
                {
                    isSeller          = false;
                    user_x_rols.rolId = 2;
                    _users_x_rols.Insert(user_x_rols);
                }
            }
            #endregion user

            //send email with the credentials
            String from         = WebConfigurationManager.AppSettings["email"];
            String fromPassword = WebConfigurationManager.AppSettings["password"];
            data.sendEmail.sendEmailOutlook(from, fromPassword, employee.email, "", "Credentials CRM", "Credentials for CRM:\nUser Name: " + userName + "\nPassword: "******"Index"));
        }
Beispiel #4
0
        public ActionResult UserNameExist(String userName)
        {
            keys _keys = new keys();

            data.AES aes = new data.AES();

            var key = _keys.GetOneById(1);

            users _users = new users();

            return(Json(new { userNameExist = _users.UserNameExist(aes.Encriptar(userName, key.C_Key, key.C_IV)) }, JsonRequestBehavior.AllowGet));
        }
Beispiel #5
0
        public ActionResult PasswordExist(String password)
        {
            var employeeId = Int64.Parse(Session["employeeId"].ToString());

            keys _keys = new keys();

            data.AES aes = new data.AES();

            var key = _keys.GetOneById(1);

            users _users = new users();

            return(Json(new { passwordExist = _users.PasswordExist(aes.Encriptar(password, key.C_Key, key.C_IV), employeeId) }, JsonRequestBehavior.AllowGet));
        }