/// <summary> /// 根据账户类型和用户名获取Model /// </summary> /// <param name="accountType">账号类型(username,email,phone)</param> /// <param name="userName">用户名</param> /// <returns></returns> public VCompanyUser GetVCompanyUserByAccountTypeAndUserName(string accountType, string userName) { VCompanyUser model = null; switch (accountType) { case "username": if (!userName.Contains("@")) { //默认登陆 model = CompanyUserDao.GetViewEntity(cu => cu.UserLname == userName && cu.CompNum == "10000"); return(model); //return null; } string[] userComp = userName.Split('@').ToArray(); if (!Utils.IsNum(userComp[1])) { return(null); } string userLName = userComp[0]; string compNum = userComp[1]; model = CompanyUserDao.GetViewEntity(cu => cu.UserLname == userLName && cu.CompNum == compNum); return(model); break; case "email": model = CompanyUserDao.GetViewEntity(cu => cu.UserEmail == userName); return(model); break; case "phone": model = CompanyUserDao.GetViewEntity(cu => cu.UserPhone == userName); return(model); break; default: return(null); break; } }
/// <summary> /// 获取当前登录的企业用户信息 2014-08-25 14:58:50 By 唐有炜 /// </summary> /// <param name="userId">userId</param> /// <returns>ResponseMessage</returns> public VCompanyUser GetCurrentCompanyUser(int userId) { var model = CompanyUserDao.GetViewEntity(cu => cu.UserId == userId); return(model); }
/// <summary> /// 公司注册 2014-08-21 14:58:50 By 唐有炜 /// </summary> /// <param name="httpContext">HttpContext</param> /// <param name="accountType">账号类型(email,phone)</param> /// <param name="userName">用户名</param> /// <param name="userPassword">密码</param> /// <returns>ResponseMessage</returns> public ResponseMessage Register(HttpContext httpContext, string accountType, string userName, string userPassword) { ResponseMessage rmsg = ValidateAccount("register", null, userName, userPassword); if (rmsg.Status) { //注册验证成功成功 //随机编号 var compNum = RandomHelper.GetComoanyNumber(); TSysCompany sysCompany = new TSysCompany() { CompNum = compNum }; userPassword = DESEncrypt.Encrypt(userPassword); string userEmail = null; string userPhone = null; switch (accountType) { case "email": userEmail = userName; break; case "phone": userPhone = userName; break; default: break; } TSysUser sysUser = new TSysUser() { CompNum = compNum, UserLname = "admin", //默认公司超级管理员用户名是admin UserPassword = userPassword, UserEmail = userEmail, UserPhone = userPhone, RoleId = 1, //默认角色 DepId = 1 //默认部门 }; if (CompanyUserDao.InsertEntities(sysCompany, sysUser)) { rmsg.Status = true; rmsg.Msg = "注册成功"; } else { rmsg.Status = false; rmsg.Msg = "注册失败"; } } //注册成功 if (rmsg.Status) { //获取用户信息 var compUser = GetVCompanyUserByAccountTypeAndUserName(accountType, userName); //书写SessionCookie WriteSessionCookie(httpContext, compUser, userName, userPassword); } return(rmsg); }
/// <summary> /// 验证用户名是否存在 2014/8/21 9:04:10 By 唐有炜 /// </summary> /// <param name="accountType">账号类型(username,email,phone)</param> /// <param name="userName">用户名</param> /// <param name="userPassword">密码</param> /// <returns></returns> public bool UserPasswordExists(string accountType, string userName, string userPassword) { bool passwordExists = false; //解密 userPassword = DESEncrypt.Encrypt(userPassword); switch (accountType) { case "username": if (!userName.Contains("@")) { var existsDefault = CompanyUserDao.ExistsViewEntity(cu => cu.UserLname == userName && cu.CompNum == "10000" && cu.UserPassword == userPassword); if (existsDefault) { return(true); } else { return(false); } } string[] userComp = userName.Split('@').ToArray(); if (!Utils.IsNum(userComp[1])) { return(false); } string userLName = userComp[0]; string compNum = userComp[1]; passwordExists = CompanyUserDao.ExistsViewEntity( cu => cu.UserLname == userLName && cu.CompNum == compNum && cu.UserPassword == userPassword); if (passwordExists) { return(true); } else { return(false); } break; case "email": passwordExists = CompanyUserDao.ExistsViewEntity( cu => cu.UserEmail == userName && cu.UserPassword == userPassword); if (passwordExists) { return(true); } else { return(false); } break; case "phone": passwordExists = CompanyUserDao.ExistsViewEntity( cu => cu.UserPhone == userName && cu.UserPassword == userPassword); if (passwordExists) { return(true); } else { return(false); } break; default: return(false); break; } }
/// <summary> /// 验证用户名是否存在 2014/8/21 9:04:10 By 唐有炜 /// </summary> /// <param name="accountType">账号类型(username,email,phone)</param> /// <param name="userName">用户名</param> /// <returns></returns> public bool UserNameExists(string accountType, string userName) { switch (accountType) { case "username": if (!userName.Contains("@")) { var existsDefault = CompanyUserDao.ExistsViewEntity(cu => cu.UserLname == userName && cu.CompNum == "10000"); if (existsDefault) { return(true); } return(false); } string[] userComp = userName.Split('@').ToArray(); if (!Utils.IsNum(userComp[1])) { return(false); } string userLName = userComp[0]; string compNum = userComp[1]; // bool userExists = CompanyUserDao.ExistsEntity(u => u.UserLname == userLName); // bool compExists = CompanyUserDao.ExistsEntity(c => c.CompNum == compNum); bool userExists = CompanyUserDao.ExistsViewEntity(u => u.UserLname == userLName && u.CompNum == compNum); // if (userExists && compExists) if (userExists) { return(true); } else { return(false); } break; case "email": bool emailExists = CompanyUserDao.ExistsViewEntity(u => u.UserEmail == userName); if (emailExists) { return(true); } else { return(false); } break; case "phone": bool phoneExists = CompanyUserDao.ExistsViewEntity(u => u.UserPhone == userName); if (phoneExists) { return(true); } else { return(false); } break; default: return(false); break; } }