public UserModel Login(UserModel model) { var UserAccount = _service.Login(model); if (Equals(UserAccount, null)) { ExceptionContent(HttpStatusCode.InternalServerError, "err_username_or_password_invalid"); } var UserProfile = _service.GetUserProfileByPhoneNumber(model.PhoneNumber); var token = new TokenModel() { Id = UserAccount.user_id, PhoneNumber = UserAccount.phone_number, Role = 1 }; return(new UserModel() { Id = UserAccount.user_id, FullName = UserProfile.full_name, PhoneNumber = UserAccount.phone_number, Email = UserAccount.email, UserCode = "UID_" + UserAccount.user_id.ToString().PadLeft(5, '0'), Token = Encrypt.Base64Encode(JsonConvert.SerializeObject(token)), Role = UserProfile.role }); }
public UserModel RegisterAdmin(UserModel model) { using (TransactionScope scope = new TransactionScope()) { var userAcc = _service.GetUserByPhoneNumber(model.PhoneNumber); if (!Equals(userAcc, null)) { ExceptionContent(HttpStatusCode.Unauthorized, "err_phone_number_already_existed"); } userAcc = new user() { phone_number = model.PhoneNumber, email = model.Email, password = Encrypt.EncodePassword(model.Password), user_id = 0, role = model.Role, store_id = 1, }; _service.SaveUser(userAcc); var UserAccount = _service.GetUserByPhoneNumber(userAcc.phone_number); var UserProfile = new user_profile() { user_profile_id = 0, address = "", phone_number = model.PhoneNumber, birthday = 0, email = model.Email, full_name = model.FullName, gender = 1, role = model.Role, user_id = UserAccount.user_id, created_date = ConvertDatetime.GetCurrentUnixTimeStamp(), }; _service.SaveUserProfile(UserProfile); UserProfile = _service.GetUserProfileByPhoneNumber(model.PhoneNumber); var token = new TokenModel() { Id = UserAccount.user_id, PhoneNumber = UserAccount.phone_number, Role = model.Role }; scope.Complete(); return(new UserModel() { Id = UserAccount.user_id, FullName = UserProfile.full_name, PhoneNumber = UserAccount.phone_number, UserCode = "UID_" + UserAccount.user_id.ToString().PadLeft(5, '0'), Token = Encrypt.Base64Encode(JsonConvert.SerializeObject(token)), Role = UserProfile.role }); } }
public ActionResult Login(AdminModel model) { if (ModelState.IsValid) { var admin = _service.LoginAdmin(model); if (Equals(admin, null)) { ViewBag.ErrorText = "Tài khoản hoặc mật khẩu không chính xác"; return(View(model)); } var token = new TokenModel() { Id = admin.admin_id, Username = admin.username, Role = admin.role }; if (Equals(Request.Cookies["PPAdmin"], null) || string.IsNullOrEmpty(Request.Cookies["PPAdmin"].Value)) { HttpCookie cookie = new HttpCookie("PPAdmin"); cookie.Value = Encrypt.Base64Encode(JsonConvert.SerializeObject(token)); cookie.Expires = DateTime.Now.AddDays(30); Response.SetCookie(cookie); } return(RedirectToAction("Blog")); } return(View(model)); }
/// <summary> /// 修改密码 /// </summary> /// <param name="mail"></param> /// <param name="password"></param> /// <returns></returns> private bool editPassword(string mail, string password) { var ret = false; var userInfoModel = this.getUserInfoModelByMail(mail, 1); if (userInfoModel != null) { userInfoModel.password = Encrypt.Base64Encode(password); var user = Mapper.Map <UserInfoModel, T_USER>(userInfoModel); ret = this._userBll.Update(user); } return(ret); }
public EmployeeModel MaidLogin(EmployeeModel model) { var employee = _service.MaidLogin(model); if (Equals(employee, null)) { ExceptionContent(HttpStatusCode.Unauthorized, "err_email_or_pass"); } var employeeTokens = _service.GetListEmployeeTokenByUDID(model.UDID); foreach (var item in employeeTokens) { _service.DeleteEmployeeToken(item); } var employeeToken = new employee_token() { employee_id = employee.employee_id, employee_token_id = 0, token = model.DeviceToken, udid = model.UDID }; _service.SaveEmployeeToken(employeeToken); var token = new TokenModel { Id = employee.employee_id, Username = employee.username, Role = employee.role }; return(new EmployeeModel { Username = employee.username, Token = Encrypt.Base64Encode(JsonConvert.SerializeObject(token)), Role = employee.role, Birthday = employee.birthday, FirstName = employee.first_name, LastName = employee.last_name, Phone = employee.phone, Code = employee.code, Statistic = new StatisticModel { Room1 = 0, Room2 = 0, Room3 = 0 } }); }
public UserRepoModel GetUser(string mail, int?status = 1, string password = null) { mail = string.IsNullOrEmpty(mail) ? mail : mail.ToLower(); UserRepoModel userRepoModel = null; var query = new DapperExQuery <T_USER>().AndWhere(t => t.U_EMAIL, OperationMethod.Equal, mail); if (!string.IsNullOrEmpty(password)) { query.AndWhere(t => t.U_PASSWORD, OperationMethod.Equal, Encrypt.Base64Encode(password)); } if (status != null) { query.AndWhere(k => k.U_STATUS, OperationMethod.Equal, 1); } var userEntity = this._userBll.GetEntity(query); if (null != userEntity) { userRepoModel = new UserRepoModel(); userRepoModel.info = Mapper.Map <T_USER, UserInfoModel>(userEntity); userRepoModel.roleList = this.getUserRoleListByUserID(userEntity.ID); } return(userRepoModel); }
public async Task <UserRepoModel> RegisterUser(string submitToken, string redisId, string mail, string password, string name, string agent) { UserRepoModel userRepoModel = null; if (await this.checkSubmitToken(EmailAuthCodeType.RegisterUser, mail, submitToken, agent)) { var thirdParty = new RelationAccountModel(); if (!string.IsNullOrEmpty(redisId)) { thirdParty = await _relationRepo.GetRelationAccountModel(redisId); if (null == thirdParty) { Enforce.Throw(new FrontInputValidateErrorException("第三方Id不存在")); } } var userInfoModel = new UserInfoModel(); userInfoModel.userName = name; userInfoModel.userTrueName = name; userInfoModel.password = Encrypt.Base64Encode(password); userInfoModel.userLevel = 0; userInfoModel.sex = 0; userInfoModel.userStatus = 1; userInfoModel.lastLoginTime = DateTime.Now; bool ret = false; var userEntity = this.getUserInfoModelByMail(mail, null); //是否存在记录(当被邀请时会生成一条占位的记录) if (userEntity == null) { userInfoModel.mail = mail.ToLower();; userInfoModel.createTime = userInfoModel.lastLoginTime; if (string.IsNullOrEmpty(name)) { userInfoModel.userName = mail.Split('@')[0]; userInfoModel.userTrueName = mail.Split('@')[0]; } var user = Mapper.Map <UserInfoModel, T_USER>(userInfoModel); if (string.IsNullOrEmpty(thirdParty.thirdPartyID)) { ret = this._userBll.Add(user); } else { if (this.getThirdPartyInfoModel(thirdParty.thirdPartyID, thirdParty.from) != null) { Enforce.Throw(new LogicErrorException("第三方账号已被其他账号绑定")); } ret = this._userBll.AddUserAndThirdParty(user, thirdParty.thirdPartyID, thirdParty.from); } userInfoModel = Mapper.Map <T_USER, UserInfoModel>(user); } else if (userEntity != null && userEntity.userStatus == 0) { userInfoModel.userID = userEntity.userID; userInfoModel.mail = userEntity.mail; userInfoModel.createTime = userEntity.createTime; if (string.IsNullOrEmpty(name)) { userInfoModel.userName = userEntity.userName; userInfoModel.userTrueName = userEntity.userTrueName; } if (string.IsNullOrEmpty(thirdParty.thirdPartyID)) { ret = this._userBll.Update(Mapper.Map <UserInfoModel, T_USER>(userInfoModel)); } else { if (this.getThirdPartyInfoModel(thirdParty.thirdPartyID, thirdParty.from) != null) { Enforce.Throw(new LogicErrorException("第三方账号已被其他账号绑定")); } ret = this._userBll.UpdateUserAndThirdParty(Mapper.Map <UserInfoModel, T_USER>(userInfoModel), thirdParty.thirdPartyID, thirdParty.from); } } if (ret) { userRepoModel = new UserRepoModel(); userRepoModel.info = userInfoModel; userRepoModel.roleList = this.getUserRoleListByUserID(userRepoModel.info.userID); } } return(userRepoModel); }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="mail"></param> /// <param name="password"></param> /// <returns></returns> private UserInfoModel getUserInfoModelByMailAndPassword(string mail, string password) { mail = string.IsNullOrEmpty(mail) ? mail : mail.ToLower(); UserInfoModel userInfoModel = null; var query = new DapperExQuery <T_USER>().AndWhere(t => t.U_EMAIL, OperationMethod.Equal, mail) .AndWhere(t => t.U_PASSWORD, OperationMethod.Equal, Encrypt.Base64Encode(password)) .AndWhere(t => t.U_STATUS, OperationMethod.Equal, 1); var userEntity = this._userBll.GetEntity(query); if (userEntity != null) { userInfoModel = Mapper.Map <T_USER, UserInfoModel>(userEntity); } return(userInfoModel); }
public async Task <IActionResult> UploadMedicalRecord([FromBody] UploadMedicalRecordInput input) { Patient patient = await dbContext.Patients.FirstOrDefaultAsync(p => p.Id == input.PatientId); if (patient == null) { return(BadRequest(Json(new { Error = "不存在该患者" }))); } InitialDiagnosis initialDiagnosis = await dbContext.InitialDiagnoses.FirstOrDefaultAsync(i => i.PatientId == patient.Id); if (initialDiagnosis == null) { return(BadRequest(Json(new { Error = "该患者未填写初步诊断" }))); } PastMedicalHistory pastMedicalHistory = await dbContext.PastMedicalHistories.FirstOrDefaultAsync(p => p.PatientId == patient.Id); if (pastMedicalHistory == null) { return(BadRequest(Json(new { Error = "该患者未填写既往史" }))); } Symptom symptom = await dbContext.Symptoms.FirstOrDefaultAsync(s => s.PatientId == patient.Id); if (symptom == null) { return(BadRequest(Json(new { Error = "该患者未填写症状体征信息" }))); } List <FoodInfo> foodInfos = await dbContext.FoodInfos.Where(f => f.PatientId == patient.Id).ToListAsync(); XmlHelper xmlHelper = new XmlHelper(); string requestXml = ""; if (input.OperationType == 3) { requestXml = xmlHelper.ConvertToXml(input.OperationType, apiOptions, patient); } else { requestXml = xmlHelper.ConvertToXml(input.OperationType, apiOptions, patient, initialDiagnosis, pastMedicalHistory, symptom, foodInfos); } ReportServiceClient reportService = new ReportServiceClient(); string responseString = await reportService.WEBRequestAsync(Encrypt.Base64Encode(requestXml)); string responseXmlString = Encrypt.Base64Decode(responseString); XmlReader xmlReader = XmlReader.Create(new StringReader(responseXmlString)); XDocument xdoc = XDocument.Load(xmlReader); UploadMedicalRecordOutput output = new UploadMedicalRecordOutput { Code = Convert.ToInt32(xdoc.Element("接口").Element("操作状态").Value), Msg = xdoc.Element("接口").Element("状态描述").Value }; if (input.OperationType == 1 && output.Code == 1) { patient.Status = "已上传"; } if (input.OperationType == 3 && output.Code == 1) { patient.Status = "正常"; } dbContext.Patients.Update(patient); dbContext.SaveChanges(); return(new ObjectResult(output)); }