Exemplo n.º 1
0
        public ActionResult UserLogin(Login model)
        {
            var vLogin = _userServices.Login(model.Name, model.Password);

            if (vLogin.IsLogin)
            {
                SetRemember(model);
                var client = Client.GetAddress();
                _userServices.AddLogin(vLogin, client.Ipv4);
                vLogin.User.Updatetime = DateTime.UtcNow;
                var identityModel = new IdentityModel <User>()
                {
                    LoginTime = DateTime.UtcNow,
                    Model     = vLogin.User
                };
                BaseIdentity.SetIdentity <User>(vLogin.SessionId, identityModel);
                model.SessionId = vLogin.SessionId;
                model.IsLogin   = true;
            }
            if (vLogin.LoginStats == LoginStats.NAME)
            {
                ViewBag.Message = "邮箱或手机号错误.";
                model.IsLogin   = false;
            }
            else if (vLogin.LoginStats == LoginStats.PASSOWRD)
            {
                ViewBag.Message = "密码错误.";
                model.IsLogin   = false;
            }
            return(View("Index", model));
        }
Exemplo n.º 2
0
        public string AddUser(string nombre, string usuario, string codigo, string passw, string search)
        {
            ResponseModel        resp;
            UserFormModel        model = new UserFormModel();
            List <UserFormModel> users = new List <UserFormModel>();

            resp = new ResponseModel();
            //RELLENAR VALUES CASE FAIL...
            //model.Supervisores = _userservices.GetSupervisores();
            //model.Codigos = _userservices.GetCodigos();
            //model.PhoneProveedores = _userservices.GetProveedores();

            //<!===========================================>
            //     CREAR LOGIN
            //<!===========================================>
            model.resp     = resp;
            model.UserName = usuario.ToLower();
            model.Codigo   = codigo.ToUpper();
            model.Nombre   = nombre;
            model.Password = passw;

            model.resp    = _userservices.AddLogin(model);
            model.LoginId = model.resp.identity;

            //trer resp.identity (loginId in case exist)
            // en case
            //model.LoginId = resp.identity;

            //<!===========================================>
            //     CREAR PROFILE
            //<!===========================================>

            model.resp = _userservices.AddProfile(model);
            // trer resp.identity (loginId in case exist)
            // en case
            model.ProfileId = resp.identity;

            if (!model.resp.response)
            {
                //ViewBag.typeMsg = "wn";
                //ViewBag.message = model.resp.message;
                return(model.resp.message);
            }

            model.ProfileId = model.resp.identity;

            //<!===========================================>
            //     CREAR USER
            //<!===========================================>


            AppUser user = new AppUser
            {
                UserName  = model.UserName,
                Email     = model.UserName + "@elaviso.com",
                ProfileId = model.ProfileId,
                LoginId   = model.LoginId
            };

            IdentityResult result = CreateUser(user, model.Password).Result;

            if (result.Succeeded)
            {
                model.Id = user.Id;
                users.Add(model);
                string sdata = "ok| Usuario Creado (" + model.LoginId.ToString() + ")" + "^";
                sdata += Objeto.SerializarLista(users, '|', '~', false);
                return(sdata);
            }
            else
            {
                return("er| " + resp.message + "| Users Mgr ");
            }
        }