public int InsertAccountUser(UserModel user) { try { SqlCommand cmd = new SqlCommand("usp_InsertAccountUser", con); cmd.Parameters.AddWithValue("@username", user.username); cmd.Parameters.AddWithValue("@email", user.email); cmd.Parameters.AddWithValue("@phone", user.phone); cmd.Parameters.AddWithValue("@password", user.password); cmd.Parameters.AddWithValue("@loggedSource", user.loggedSource); cmd.Parameters.AddWithValue("@userType", user.userType); cmd.Parameters.AddWithValue("@status", user.status); cmd.CommandType = CommandType.StoredProcedure; con.Open(); int ret = cmd.ExecuteNonQuery(); con.Close(); return ret; } catch { return -99; } finally { con.Close(); } }
private static void setUserSession(UserModel user) { HttpContext.Current.Session[AppConstants.SESSION_UNIQUE_ID] = user.sessionId; HttpContext.Current.Session[AppConstants.SESSION_USER_ID] = user.id; HttpContext.Current.Session[AppConstants.SESSION_USERNAME] = user.username; HttpContext.Current.Session[AppConstants.SESSION_EMAIL_ID] = user.email; HttpContext.Current.Session[AppConstants.SESSION_USER_TYPE] = user.userType; }
public static String ForgotPassword(String email) { UserDAL dal = new UserDAL(); JavaScriptSerializer ser = new JavaScriptSerializer(); UserModel user = new UserModel(); try { String pass = CreatePassword(6); int i = dal.ChangePassword(email,pass); if (i >= 1) { user.errorCode = (int)Errors.ChangePasswordSuccess; user.errorMessage = "We have successfully change the password, Please check your mail for updated password."; setUserSession(user); EmailUtil.ForgotPasswordEmail(email, "", pass); } else { user.errorCode = (int)Errors.ChangePasswordError; user.errorMessage = "Invalid Email id or Phone #"; } } catch { user.errorCode = (int)Errors.ChangePasswordError; user.errorMessage = "Data already Exist."; } return ser.Serialize(user); }
public static String Register(String username, String email, String phone, String data) { UserDAL dal = new UserDAL(); JavaScriptSerializer ser = new JavaScriptSerializer(); UserModel user = new UserModel(); try { user.username = username; user.password = CreatePassword(6); user.email = email; user.phone = phone; user.sessionId = user.UniqueId(); user.loggedSource = LeadSource.Direct.ToString(); user.userType = UserType.Guest.ToString(); user.status = AppConstants.ACTIVATE; int i = dal.InsertAccountUser(user); if (i >= 1) { user.id = i+""; user.errorCode = (int)Errors.RegisterSuccess; user.errorMessage = "Welcome " + username; setUserSession(user); //Send Email and Send SMS EmailUtil.RegisterEmail(user.email, user.username, user.password); } else { user.errorCode = (int)Errors.RegisterError; user.errorMessage = "User already exist, Please provide the unique details"; } } catch { user.errorCode = (int)Errors.RegisterError; user.errorMessage = "Data already Exist."; } return ser.Serialize(user); }
public static String Login(String username,String password,String data) { UserDAL dal = new UserDAL(); JavaScriptSerializer ser = new JavaScriptSerializer(); UserModel user = new UserModel(); try { DataTable dt = dal.GetAccountUser(username, password); if (dt != null || dt.Rows.Count <= 1) { user.id = dt.Rows[0]["id"].ToString(); user.username = dt.Rows[0]["username"].ToString(); user.password = dt.Rows[0]["password"].ToString(); user.email = dt.Rows[0]["email"].ToString(); user.phone = dt.Rows[0]["phone"].ToString(); user.isEmailVerfied = dt.Rows[0]["isEmailVerfied"].ToString(); user.isPhoneVerfied = dt.Rows[0]["isPhoneVerfied"].ToString(); user.emailOTP = dt.Rows[0]["emailOTP"].ToString(); user.phoneOTP = dt.Rows[0]["phoneOTP"].ToString(); user.name = dt.Rows[0]["name"].ToString(); user.dob = dt.Rows[0]["dob"].ToString(); user.profile = dt.Rows[0]["profile"].ToString(); user.loggedSource = dt.Rows[0]["loggedSource"].ToString(); user.userType = dt.Rows[0]["userType"].ToString(); user.status = dt.Rows[0]["status"].ToString(); user.createdDate = dt.Rows[0]["createdDate"].ToString(); user.errorCode = (int)Errors.LoginSuccess; user.errorMessage = "Success Login"; user.sessionId = user.UniqueId(); //Set User Session setUserSession(user); } else { user.errorCode = (int)Errors.LoginError; user.errorMessage = "Invalid Login Details"; } } catch { user.errorCode = (int)Errors.LoginError; user.errorMessage = "Invalid Login Details"; } return ser.Serialize(user); }