public async Task <authData> resetPwd(ResetViewModel reset) { authData adata = new authData(); Utility utility = new Utility(appsetting, context); try { string pwd = Utility.RandomString(appsetting.Value.pLength); var ot = await utility.resetUser(reset); if (ot != null) { //ot.password = hashPass(pwd); if (ot._id > 0) { //call notification service adata.message = "success"; } } } catch (Exception ex) { Console.Write(ex.ToString()); } return(adata); }
/// <summary> /// 查询单个模型实体 /// </summary> /// <param name="id">objectId</param>); /// <returns>实体</returns>); public authData QuerySingleById(string objectId) { const string sql = "SELECT TOP 1 objectId,weiboId,qqId,alibabaId from authData WHERE [objectId] = @objectId"; using (var reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@objectId", objectId))) { if (reader.HasRows) { reader.Read(); authData model = SqlHelper.MapEntity <authData>(reader); if (reader["alibabaId"] != DBNull.Value) { alibabaDAO alibabaDAO = new alibabaDAO(); model.alibaba = alibabaDAO.QuerySingleById((string)reader["alibabaId"]); } if (reader["qqId"] != DBNull.Value) { qqDAO qqDAO = new qqDAO(); model.qq = qqDAO.QuerySingleById((string)reader["qqId"]); } if (reader["weiboId"] != DBNull.Value) { weiboDAO weiboDAO = new weiboDAO(); model.weibo = weiboDAO.QuerySingleById((string)reader["weiboId"]); } return(model); } else { return(null); } } }
///<summary> ///分页查询一个集合 ///</summary> ///<param name="index">页码</param> ///<param name="size">页大小</param> ///<param name="wheres">条件匿名类</param> ///<param name="orderField">排序字段</param> ///<param name="isDesc">是否降序排序</param> ///<returns>实体集合</returns> public IEnumerable <authData> QueryList(int index, int size, object wheres = null, string orderField = "objectId", bool isDesc = true) { List <SqlParameter> list = null; string where = wheres.parseWheres(out list); orderField = string.IsNullOrEmpty(orderField) ? "objectId" : orderField; var sql = SqlHelper.GenerateQuerySql("authData", new string[] { "objectId", "weiboId", "qqId", "alibabaId" }, index, size, where, orderField, isDesc); using (var reader = SqlHelper.ExecuteReader(sql, list.ToArray())) { if (reader.HasRows) { while (reader.Read()) { authData model = SqlHelper.MapEntity <authData>(reader); if (reader["alibabaId"] != DBNull.Value) { alibabaDAO alibabaDAO = new alibabaDAO(); model.alibaba = alibabaDAO.QuerySingleById((string)reader["alibabaId"]); } if (reader["qqId"] != DBNull.Value) { qqDAO qqDAO = new qqDAO(); model.qq = qqDAO.QuerySingleById((string)reader["qqId"]); } if (reader["weiboId"] != DBNull.Value) { weiboDAO weiboDAO = new weiboDAO(); model.weibo = weiboDAO.QuerySingleById((string)reader["weiboId"]); } yield return(model); } } } }
///<summary> ///向数据库中添加一条记录 ///</summary> ///<param name="model">要添加的实体</param> public bool Insert(authData model) { const string sql = @"INSERT INTO [dbo].[authData] (objectId,weiboId,qqId,alibabaId) VALUES (@objectId,@weiboId,@qqId,@alibabaId)"; int res = SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@weiboId", model.weibo.objectId.ToDBValue()), new SqlParameter("@qqId", model.qq.objectId.ToDBValue()), new SqlParameter("@alibabaId", model.alibaba.objectId.ToDBValue())); return(res > 0); }
/// <summary> /// 根据主键更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>执行结果受影响行数</returns> public bool Update(authData model) { return(_dao.Update(model)); }
/// <summary> /// 向数据库中添加一条记录 /// </summary> /// <param name="model">要添加的实体</param> /// <returns>是否成功</returns> public bool Insert(authData model) { return(_dao.Insert(model)); }
/// <summary> /// 根据主键更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>是否成功</returns> public bool Update(authData model) { const string sql = @"UPDATE [dbo].[authData] SET weiboId=@weiboId,qqId=@qqId,alibabaId=@alibabaId WHERE [objectId] = @objectId"; return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@objectId", model.objectId.ToDBValue()), new SqlParameter("@weiboId", model.weibo.objectId.ToDBValue()), new SqlParameter("@qqId", model.qq.objectId.ToDBValue()), new SqlParameter("@alibabaId", model.alibaba.objectId.ToDBValue())) > 0); }
//[AllowAnonymous] //[ValidateAntiForgeryToken] public async Task <IActionResult> Login(LoginViewModel login, string submit) { DAC dac = new DAC(appsetting, HttpContext); authData adata = new authData(); if (submit == "Login") { login.emailautofocus = "autofocus"; login.changepwdautofocus = ""; login.changediv = "none"; login.logindiv = "block"; login.resetdiv = "none"; login.passdiv = "block"; if (!ModelState.IsValid) { login.Message = "Login Failed"; return(View(login)); } try { adata = await dac.Login(login); } catch (Exception) { } login.Message = adata.message; if (adata.isAuth) { if (adata.isFirstLogin) { login.changediv = "block"; login.logindiv = "none"; login.emailautofocus = ""; login.changepwdautofocus = "autofocus"; login.Message = ""; login.Email = adata.email; login.Password = adata.password; login.id = adata.userid; return(View(login)); } HttpContext.Session.SetString("_email", adata.email); HttpContext.Session.SetString("_username", adata.username); Index index = new Models.Index() { authdata = adata, user = new Models.User() }; return(View("Index", index)); } } if (submit == "Change") { login.changepwdautofocus = "autofocus"; login.emailautofocus = ""; login.passwordautofocus = ""; login.confirmpwdautofocus = ""; login.changediv = "block"; login.logindiv = "none"; login.resetdiv = "none"; login.passdiv = "block"; if (string.IsNullOrEmpty(login.Email)) { login.changepwdautofocus = ""; login.emailautofocus = "autofocus"; login.passwordautofocus = ""; login.confirmpwdautofocus = ""; login.Message = "Enter Email"; return(View(login)); } if (string.IsNullOrEmpty(login.Password)) { login.changepwdautofocus = ""; login.emailautofocus = ""; login.passwordautofocus = "autofocus"; login.confirmpwdautofocus = ""; login.Message = "Enter Old Password"; return(View(login)); } if (string.IsNullOrEmpty(login.Changepwd)) { login.Message = "Enter New Password"; return(View(login)); } if (string.IsNullOrEmpty(login.Confirmpwd)) { login.changepwdautofocus = ""; login.emailautofocus = ""; login.passwordautofocus = ""; login.confirmpwdautofocus = "autofocus"; login.Message = "Confirm New Password"; return(View(login)); } if (login.Changepwd.Length < 8) { login.Message = "New Password must be at least 8 characters"; return(View(login)); } if (login.Changepwd != login.Confirmpwd) { login.Message = "Password Mismatch"; return(View(login)); } try { adata = await dac.activateUser(login); } catch (Exception ex) { Console.Write(ex.ToString()); } if (adata.isAuth) { login.emailautofocus = "autofocus"; login.changepwdautofocus = ""; login.changediv = "none"; login.logindiv = "block"; login.resetdiv = "none"; login.passdiv = "block"; Index index = new Models.Index() { authdata = adata, user = new Models.User() }; return(View("Index", index)); } else { login.Message = "Authentication Failed"; return(View(login)); } } return(View(login)); }