public ActionResult Login(LoginModel loggedinUser)
        {
            UserBusinessLogic _user = new UserBusinessLogic();
            User foundUser          = new User();

            if (ModelState.IsValid)
            {
                foundUser.UserName = loggedinUser.Username;
                foundUser.Password = loggedinUser.Password;

                ResultUser _result = _user.checkingUserInDB(foundUser);

                if (_user.checkingUserInDB(foundUser) != null)
                {
                    UserModel loggingUserIN = Mapping.Mapper.UserToUserModel(_result.User);

                    Session["UserSession"] = loggingUserIN;

                    return(RedirectToAction("Search", "Home"));
                }
                else
                {
                    loggedinUser.DialogMessage     = _result.Message;
                    loggedinUser.DialogMessageType = _result.Type.ToString();
                    return(View(loggedinUser));
                }
            }
            return(View(loggedinUser));
        }
예제 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ResultUser()
                {
                    UserName = model.UserName, Email = model.Email
                };
                //创建用户是需要带密码进入,否则密码保存失败,返回时Identity
                //Succeeded 属性代表了操作成功了
                //Errors 属性,包含了IdentityErrors对象的集合,描述了错误信息
                var result = await UserManager.CreateAsync(user, model.PassWord);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User {userName} 注册", model.UserName);
                    return(RedirectToAction("Login"));
                }

                //如果没有登录成功就会执行下面添加错误信息
                foreach (var error in result.Errors)
                {
                    //第二个参数为错误信息
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
        public ResultUser LoginUser(User userToCheck)
        {
            string      salt;
            string      hashed     = "";
            ResultUser  r          = new ResultUser();
            List <User> users      = BLGetUsers();
            User        _foundUser = new User();

            foreach (User current in users)
            {
                if (current.UserName == userToCheck.UserName)
                {
                    _foundUser = current;
                }
            }

            //User _foundUser = users.Where(u => u.UserName == userToCheck.UserName).FirstOrDefault();

            if (_foundUser != null)
            {
                salt = _foundUser.Salt;

                hashed = hash.ComputeSHA256Hash(salt + userToCheck.Password);
            }

            if (hashed == _foundUser.Password)
            {
                r.User = _foundUser;
            }

            return(r);
        }
예제 #4
0
        public JsonResult  LoginInfo()
        {
            ResultUser    resultUser = new ResultUser();
            UserBLL       ub         = new UserBLL();
            InvitationBLL ib         = new InvitationBLL();

            try
            {
                string username = Request["username"].ToString();
                string password = Request["password"].ToString();
                User   user     = new User();
                user.LoginID = username;
                var data = ub.GetUser(user);
                if (data != null)
                {
                    if (data.LoginID.Equals(username) && data.PassWord.Equals(MD5Helper.MD5Encrypt32(password)))
                    {
                        resultUser.res = 200;
                        resultUser.msg = "用户是登录的私密聊天";
                        DateTime time = DateTime.Now;
                        resultUser.data = JwtHelper.CreateToken(user, time);
                    }
                    else
                    {
                        resultUser.res = 500;
                        resultUser.msg = "密码错误,请重新输入";
                    }
                }
            }
            catch
            {
            }
            return(Json(resultUser));
        }
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User();
                user.UserName = model.UserName;
                user.Password = model.Password;


                ResultUser _result = userBL.LoginUser(user);


                UserModel _userModel = Mapper.UserToUserModel(_result.User);


                Session["UserSession"] = _userModel;


                return(RedirectToAction("Search", "Home"));
            }

            else
            {
                return(View(model));
            }
        }
        public JsonResult QueryDictionary()
        {
            ResultUser resultUser = new ResultUser();
            bool       flag       = false;

            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                string json = sr.ReadToEnd();
                if (string.IsNullOrEmpty(json))
                {
                }
                else
                {
                    flag = true;
                    obj  = JObject.Parse(json);
                }
            }
            if (flag)
            {
                string name = GetParams("name");
                resultUser.res  = 200;
                resultUser.msg  = "查询成功";
                resultUser.data = IDDC.Query(name);
                return(Json(resultUser, JsonRequestBehavior.AllowGet));
            }
            else
            {
                resultUser.res  = 200;
                resultUser.msg  = "查询成功";
                resultUser.data = IDDC.Query();
                return(Json(resultUser, JsonRequestBehavior.AllowGet));
            }
        }
예제 #7
0
        public async Task <ResultListData <ResultUser> > List()
        {
            var result = new ResultListData <ResultUser>()
            {
                data  = new List <ResultUser>(),
                code  = 0,
                msg   = "",
                count = 100
            };

            for (int i = 0; i < 100; i++)
            {
                ResultUser resultUser = new ResultUser();
                resultUser.id         = i;
                resultUser.username   = "******" + i.ToString();
                resultUser.sex        = i % 2 == 0 ? "女" : "男";
                resultUser.city       = "城市-" + i.ToString();
                resultUser.sign       = "签名-" + i.ToString();
                resultUser.experience = 255;
                resultUser.logins     = 24;
                resultUser.wealth     = 83289381;
                resultUser.classify   = "作家";
                resultUser.score      = 55;
                result.data.Add(resultUser);
                result.count = result.data.Count();
            }
            return(result);
        }
        public ResultUser LoginUserPassThru(LibraryCommon.DataEntity.User inUser)
        {
            ResultUser r = new ResultUser();
            string     _hashed = "", _salt = "";
            Hasher     _hasher = new Hasher();

            // 1. get the users
            List <LibraryCommon.DataEntity.User> _list = _data.GetUsers();

            // 2. find this user by username , assume there's not dups
            LibraryCommon.DataEntity.User _foundUser = _list.Where(u => u.UserName == inUser.UserName).
                                                       FirstOrDefault();

            // 3. if user match is found, get the salt
            if (_foundUser != null)
            {
                _salt = _foundUser.Salt;
                // 4. run hash process for this password with the salt
                _hashed = _hasher.HashedValue(_salt + inUser.Password);
            }
            else
            {
                // no found user, no salt
            }


            // 5. compare the hashes
            if (_hashed == _foundUser.Password)
            {
                // 6. if match, we have a user with a role
                r.User = _foundUser;
                r.Type = ResultType.Success;
            }
            else
            {
                // 7. otherwise no match and return a error message
                r.User    = null;
                r.Message = "Username not found or password did not match.";
                r.Type    = ResultType.Failure;
            }

            return(r);
        }
        public ActionResult Login(LoginModel inModel)
        {
            if (ModelState.IsValid)
            {
                // 3. send the input down to the database and check for username/password

                // 3.a create new bll object
                //UserOperationsBLL _logic = new UserOperationsBLL(base.Connection);

                // 3.b need to convert LoginModel object to User object
                LibraryCommon.DataEntity.User _user = Mapper.LoginModelToUser(inModel);

                // 3.c pass the user object down to bll layer
                //ResultUsers _result = _userOperationsBLL.LoginUser(_user);
                ResultUser _result = _logic.LoginUserPassThru(_user);

                if (_result.Type == ResultType.Success)
                {
                    UserModel _userModel = Mapper.UserToUserModel(_result.User);

                    // store the userModel in Global session
                    Session["UserSession"] = _userModel;

                    // Advanced Auth LMS
                    // Session["AUTHUsername"] = _userModel.Username;
                    // Session["AUTHRoles"] = _userModel.RoleName;

                    return(RedirectToAction("Search", "Home"));
                }
                else
                {
                    inModel.DialogMessage     = _result.Message;
                    inModel.DialogMessageType = _result.Type.ToString();
                    return(View(inModel));
                }
            }
            // validation failed, have the user redo the form
            else
            {
                return(View(inModel));
            }
        }
예제 #10
0
        //public ActionResult CongratulationsView()
        //{
        //    return View();
        //}


        public ActionResult CongratulationsView()
        {
            ResultUser resultUser = new ResultUser();
            ArrayList  result     = new ArrayList();

            var           item           = _userDb.Users.Where(u => u.Name == User.Identity.Name).FirstOrDefault();
            var           _itemTest      = _testDb.Tests.Where(t => t.ClientsId == item.Id);
            int           rightAnswer    = 0;
            int           lieAnswer      = 0;
            int           countQuastions = Answers.Count;
            List <string> answerUser     = new List <string>();

            foreach (var temp in _itemTest)
            {
                resultUser.DateComplete = temp.DateComplete;
                answerUser.Add(temp.CapitalKZ);
                answerUser.Add(Convert.ToString(temp.CountCityKZ));
                answerUser.Add(temp.LanguageKZ);
                answerUser.Add(Convert.ToString(temp.DateFounded));
                break;
            }
            int count = -1;

            foreach (var list in Answers.Values)
            {
                count++;
                if (list.Contains(answerUser[count]))
                {
                    rightAnswer++;
                }
            }
            lieAnswer              = countQuastions - rightAnswer;
            resultUser.Name        = User.Identity.Name;
            resultUser.RightAnswer = rightAnswer;
            resultUser.LieAnswer   = lieAnswer;
            int tempProsent = 100 / countQuastions;
            int prosent     = rightAnswer * tempProsent;

            resultUser.Porsent = prosent;

            return(View(resultUser));
        }
        public async Task <Dictionary <bool, string> > IsAuthenticated(LoginRequestDTO request)
        {
            var token = string.Empty;

            if (!_userService.IsValid(request))
            {
                return new Dictionary <bool, string> {
                           { false, "" }
                }
            }
            ;
            var resultUser = new ResultUser {
                UserName = request.Username
            };
            //bool result = await UserManager.CheckPasswordAsync(resultUser, request.Password);
            //var result = await SignInManager.CheckPasswordSignInAsync(resultUser, request.Password, false);
            var result = await SignInManager.PasswordSignInAsync(request.Username, request.Password, false, lockoutOnFailure : false);

            if (result.Succeeded)
            {
                var claims = new[]
                {
                    new Claim(ClaimTypes.Name, request.Username)
                };

                var key         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_tokenManagement.Secret));
                var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
                var jwtToken    = new JwtSecurityToken(_tokenManagement.Issuer, _tokenManagement.Audience, claims, expires: DateTime.Now.AddMinutes(_tokenManagement.AccessExpiration), signingCredentials: credentials);

                token = new JwtSecurityTokenHandler().WriteToken(jwtToken);

                return(new Dictionary <bool, string> {
                    { true, token }
                });
            }
            else
            {
                return(new Dictionary <bool, string> {
                    { false, "" }
                });
            }
        }
예제 #12
0
        //注册
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var user = new ResultUser {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.PassWord);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User {usserName} was created.", model.UserName);
                    return(RedirectToAction("Login"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
        public async Task <Dictionary <bool, string> > Register(RegisterRequestDTO request)
        {
            var user = new ResultUser {
                UserName = request.UserName, Email = request.Email
            };
            var result = await UserManager.CreateAsync(user, request.Password);

            if (result.Succeeded)
            {
                return(new Dictionary <bool, string> {
                    { true, "success" }
                });
            }
            else
            {
                return(new Dictionary <bool, string> {
                    { false, result.Errors.FirstOrDefault().Description }
                });
            }
            //result.Errors.
        }
        public ResultUser checkingUserInDB(User loggingIn)
        {
            ResultUser r = new ResultUser();

            List <User> checkingUsers = GetUsersPassThru();
            User        foundUser     = new User();

            string Hash         = " ";
            string SaltPassword = "******";

            foreach (var i in checkingUsers)
            {
                if (loggingIn.UserName == i.UserName)
                {
                    foundUser = i;
                }
            }

            SaltPassword = foundUser.Salt + loggingIn.Password;

            Hasher hashingSAndP = new Hasher();

            Hash = hashingSAndP.ComputeSHA256Hash(SaltPassword);

            if (foundUser.Password == Hash)
            {
                r.User = foundUser;
                r.Type = ResultType.Success;
            }
            else
            {
                r.User    = null;
                r.Message = "Username not found or password did not match.";
                r.Type    = ResultType.Failure;
            }

            return(r);
        }
예제 #15
0
        public JsonResult Login()
        {
            ResultUser    resultUser = new ResultUser();
            UserBLL       ub         = new UserBLL();
            InvitationBLL ib         = new InvitationBLL();

            try
            {
                using (StreamReader sr = new StreamReader(Request.InputStream))
                {
                    string json = sr.ReadToEnd();
                    if (string.IsNullOrEmpty(json))
                    {
                        resultUser.msg = "没有获取到用户名和密码";
                        return(Json(resultUser));
                    }
                    obj = JObject.Parse(json);
                }
                string pw       = obj["password"].ToString();
                string password = MD5Helper.MD5Encrypt32(pw);
                string loginid  = obj["loginid"].ToString();
                Regex  r1       = new Regex(@"^[a-zA-Z0-9_\u4e00-\u9fa5]{4,16}$");
                User   user     = new User();
                if (r1.IsMatch(loginid))
                {
                    user.LoginID = loginid;
                }
                else
                {
                    resultUser.msg = "登录名格式不对";
                    return(Json(resultUser));
                };
                dynamic push     = JsonConvert.DeserializeObject(obj["push"].ToString());
                string  token    = push.token;
                string  clientid = push.clientid;
                if (string.IsNullOrEmpty(token))
                {
                    resultUser.msg = "登录失败";
                    return(Json(resultUser));
                }
                user = ub.GetUser(user);
                if (user == null)
                {
                    resultUser.msg = "该用户不存在";
                    return(Json(resultUser));
                }
                else
                {
                    DateTime time  = DateTime.Now;
                    bool     value = false;
                    if (string.IsNullOrEmpty(user.PassWords))
                    {
                        user.PassWords = MD5Helper.MD5Encrypt32("1111");
                        if (ub.UpdatePassword(user))
                        {
                            value = true;
                        }
                    }
                    var result = redis.StringGet(user.ID.ToString());
                    if (result != null)
                    {
                        string results = result["clientid"].ToString();
                        if (!results.Equals(clientid))
                        {
                            //如果该账户已经登录则通过第三方推送将消息通知给上一个用户
                            var users = ub.GetUserName(user.LoginID);
                            var datas = redis.StringGet(users.ID.ToString());
                            if (datas != null)
                            {
                                string device    = datas["device"].ToString();
                                string clientids = datas["clientid"].ToString();
                                var    datass    = new
                                {
                                    title = "该账号已在其他地方登录"
                                };
                                var PenetrateMsg = new
                                {
                                    type = 0,
                                    data = datass
                                };
                                if ("2".Equals(device))
                                {
                                    Push.IosPushMessageToSingle(JsonConvert.SerializeObject(PenetrateMsg), clientids);
                                }
                                else if ("1".Equals(device))
                                {
                                    Push.IosPushMessageToSingle(JsonConvert.SerializeObject(PenetrateMsg), clientids);
                                }
                                else
                                {
                                    resultUser.msg = "当前登录的是其他设备";
                                    return(Json(resultUser));
                                }
                            }
                        }
                    }
                    if (password.Equals(user.PassWord))
                    {
                        if (value)
                        {
                            resultUser.res   = 205;
                            resultUser.state = 1;
                            resultUser.msg   = "由于您未设置迷惑密码系统帮您设置了迷惑密码为1111";
                            resultUser.data  = JwtHelper.CreateToken(user, time);
                            ub.UpdateUser(user.ID, time);
                            //用redis保存用户登录的信息
                            redis.StringSet(user.LoginID, user);
                        }
                        int res   = CheckAgent();
                        var datas = new
                        {
                            device   = res,
                            token    = token,
                            clientid = clientid
                        };
                        redis.StringSet(user.ID.ToString(), datas);
                        resultUser.res   = 200;
                        resultUser.state = 1;
                        resultUser.msg   = "用户是登录的正常聊天";
                        resultUser.data  = JwtHelper.CreateToken(user, time);
                        ub.UpdateUser(user.ID, time);
                        //用redis保存用户登录的信息
                        redis.StringSet(user.LoginID, user);
                    }
                    else if (password.Equals(user.PassWords))
                    {
                        resultUser.res   = 200;
                        resultUser.state = 2;
                        resultUser.msg   = "用户是登录的私密聊天";
                        ub.EditChatSwitch(user.ID);
                        ub.UpdateUser(user.ID, time);
                        resultUser.data = JwtHelper.CreateToken(user, time);
                    }
                    else
                    {
                        resultUser.res = 500;
                        resultUser.msg = "密码错误,请重新输入";
                    };
                }
            }
            catch (HttpException ex)
            {
                LogHelper.WriteLog(ex.Message.ToString(), ex);
            }
            return(Json(resultUser));
        }
예제 #16
0
        public JsonResult Register()
        {
            ResultUser    resultUser = new ResultUser();
            UserBLL       ub         = new UserBLL();
            InvitationBLL ib         = new InvitationBLL();

            try
            {
                using (StreamReader sr = new StreamReader(Request.InputStream))
                {
                    string json = sr.ReadToEnd();
                    if (string.IsNullOrEmpty(json))
                    {
                        resultUser.msg = "没有获取到用户名和密码和邀请码";
                        return(Json(resultUser));
                    }
                    obj = JObject.Parse(json);
                }
                string loginid = obj["loginid"].ToString();
                Regex  r1      = new Regex(@"^[a-zA-Z0-9_\u4e00-\u9fa5]{4,16}$");
                if (!r1.IsMatch(loginid))
                {
                    resultUser.msg = "用户名格式不对";
                    return(Json(resultUser));
                }
                bool msg = ub.GetUserIsRegister(loginid);
                if (msg)
                {
                    resultUser.msg = "该用户名已被注册";
                    return(Json(resultUser));
                }
                ;
                int        InviteCode = int.Parse(obj["invitecode"].ToString());
                Invitation invitation = new Invitation()
                {
                    InviteCode = InviteCode,
                };
                Invitation ivs = ib.GetInvitation(invitation);
                if (ivs == null)
                {
                    resultUser.msg = "该邀请码不存在";
                    return(Json(resultUser));
                }
                if (ivs.EndTime < DateTime.Now)
                {
                    resultUser.msg = "邀请码已过期";
                    return(Json(resultUser));
                }
                var     password = obj["password"].ToString();
                dynamic push     = JsonConvert.DeserializeObject(obj["push"].ToString());
                string  token    = push.token;
                string  clientid = push.clientid;
                if (string.IsNullOrEmpty(token))
                {
                    resultUser.msg = "注册失败";
                    return(Json(resultUser));
                }
                if (ivs != null)
                {
                    DateTime time   = DateTime.Now;
                    Random   random = new Random();
                    int      result = random.Next(2, 8);
                    User     user   = new User();
                    user.LoginID           = loginid;
                    user.PassWord          = MD5Helper.MD5Encrypt32(password);
                    user.HeadPortrait      = "/Images/head/" + result + ".jpg";
                    user.PSearchState      = false;
                    user.USearchState      = true;
                    user.BurnAfterReading  = false;
                    user.ThemeTypeID       = 1;
                    user.SecondThemeTypeID = 1;
                    user.IsEnterSendMsg    = false;
                    user.ChatTimeLimit     = "0";
                    user.Shape             = 1;
                    user.ChatSwitch        = false;
                    user.LastLoginAt       = time;
                    if (ub.CreateUser(user))
                    {
                        var data = ub.GetUserName(loginid);
                        int res  = CheckAgent();

                        var datas = new
                        {
                            device   = res,
                            token    = token,
                            clientid = clientid
                        };
                        redis.StringSet(data.ID.ToString(), datas);
                        redis.StringSet(user.LoginID, user);
                        ib.DeleteInvitation(InviteCode);
                        resultUser.res  = 200;
                        resultUser.msg  = "注册成功";
                        resultUser.data = JwtHelper.CreateToken(user, time);
                        return(Json(resultUser));
                    }
                }
            }
            catch (HttpException ex)
            {
                LogHelper.WriteLog(ex.Message.ToString(), ex);
            }
            return(Json(resultUser));
        }
예제 #17
0
파일: SYS_Users.cs 프로젝트: kkwkk/ybyzt
    /// <summary>
    /// 经销商登录
    /// </summary>
    /// <param name="JSon"></param>
    /// <returns></returns>
    public ResultDisLog ResellerLogin(string JSon)
    {
        try
        {
            #region JSon取值

            string LoginName  = string.Empty;
            string PassWord   = string.Empty;
            string AndroidKey = string.Empty;
            string IOSKey     = string.Empty;

            JsonData JInfo = JsonMapper.ToObject(JSon);
            if (JInfo.Count > 0 && JInfo["LoginName"].ToString() != "" && JInfo["PassWord"].ToString() != "")
            {
                LoginName = JInfo["LoginName"].ToString();
                PassWord  = JInfo["PassWord"].ToString();
                //AndroidKey = JInfo["AndroidKey"].ToString();
                //IOSKey = JInfo["IOSKey"].ToString();
            }
            else
            {
                return(new ResultDisLog()
                {
                    Result = "F", Description = "参数为空异常"
                });
            }

            #endregion

            List <Hi.Model.SYS_Users> userList = new Hi.BLL.SYS_Users().GetList("",
                                                                                " UserName='******' and AuditState =2 and dr=0 and IsEnabled = 1", "");
            if (userList == null || userList.Count != 1)
            {
                return new ResultDisLog()
                       {
                           Result = "F", Description = "账号密码错误"
                       }
            }
            ;

            List <ResultUser> UserList = new List <ResultUser>();
            var user = userList[0];

            if (user.UserPwd != PassWord)
            {
                return new ResultDisLog()
                       {
                           Result = "F", Description = "账号密码错误"
                       }
            }
            ;

            List <Hi.Model.SYS_CompUser> compUserList = new Hi.BLL.SYS_CompUser().GetList("",
                                                                                          "UserID='" + user.ID + "' and IsNull(dr,0)=0 ", "");
            if (compUserList != null && compUserList.Count > 0)
            {
                foreach (var compUser in compUserList)
                {
                    Hi.Model.BD_Company comp = new Hi.BLL.BD_Company().GetModel(compUser.CompID);

                    if (comp == null)
                    {
                        return new ResultDisLog()
                               {
                                   Result = "F", Description = "企业异常"
                               }
                    }
                    ;

                    ResultUser resultUser = new ResultUser();
                    resultUser.UserID   = user.ID.ToString();
                    resultUser.TrueName = user.TrueName;
                    resultUser.Sex      = user.Sex;
                    resultUser.Phone    = user.Phone;
                    if (compUser.DisID != 0)
                    {
                        Hi.Model.BD_Distributor dis = new Hi.BLL.BD_Distributor().GetModel(compUser.DisID);

                        if (dis == null)
                        {
                            return new ResultDisLog()
                                   {
                                       Result = "F", Description = "经销商异常"
                                   }
                        }
                        ;
                        resultUser.ResellerID   = compUser.DisID.ToString();
                        resultUser.ResellerName = dis.DisName;
                    }
                    resultUser.IsEnabled   = user.IsEnabled.ToString();
                    resultUser.Erptype     = comp.Erptype.ToString();
                    resultUser.ConpamyID   = compUser.CompID.ToString();
                    resultUser.CompanyName = comp.CompName;
                    if (user.Type == 1 || user.Type == 5)
                    {
                        resultUser.UserType = "0"; //0:经销商 1:核心企业
                    }
                    else if (user.Type == 3 || user.Type == 4)
                    {
                        resultUser.UserType = "1"; //0:经销商 1:核心企业
                    }
                    UserList.Add(resultUser);
                }
            }
            return(new ResultDisLog()
            {
                Result = "T",
                Description = "登录成功",
                UserList = UserList
            });
        }
        catch
        {
            Common.CatchInfo(JSon, "ResellerLogin");
            return(new ResultDisLog()
            {
                Result = "F", Description = "参数异常"
            });
        }
    }